*/
#include <stddef.h>
#include <dpl/encryption/resource_decryption.h>
-#ifdef Try
-#undef Try
-#endif
-#include <FSecSecretKey.h>
-#include <security/FSec_DeviceKeyGenerator.h>
#include <fcntl.h>
#include <string>
#include <dpl/log/log.h>
#include <dpl/exception.h>
+#include <dukgen.h>
namespace {
#define BITS_SIZE 128
#define KEY_SIZE 16
}
-
-namespace WRTDecryptor{
+namespace WRTDecryptor {
ResourceDecryptor::ResourceDecryptor()
{
LogDebug("Started Decryption");
}
ResourceDecryptor::~ResourceDecryptor()
-{
-}
+{}
void ResourceDecryptor::SetDecryptionKey(std::string userKey)
{
if (userKey.empty()) {
return;
}
- using namespace Tizen;
- using namespace Tizen::Base;
- Tizen::Base::String appId;
- appId.Format(userKey.size(), L"%s", userKey.c_str());
- Tizen::Security::ISecretKey* pSecretKey =
- Tizen::Security::_DeviceKeyGenerator::GenerateDeviceKeyN(appId, KEY_SIZE);
+ char* pKey = GetDeviceUniqueKey(const_cast<char*>(userKey.c_str()),
+ userKey.size(), KEY_SIZE);
- Tizen::Base::ByteBuffer* bf = pSecretKey->GetEncodedN();
- unsigned char *key = new unsigned char[KEY_SIZE+1];
+ unsigned char *key = reinterpret_cast<unsigned char*>(pKey);
- int i=0;
- while(bf->HasRemaining()) {
- byte b;
- bf->GetByte(b);
- key[i] = b;
- i++;
- }
- key[KEY_SIZE] = '\n';
-
- if ( 0 > AES_set_decrypt_key(key, BITS_SIZE, &m_decKey)) {
- delete key;
+ if (0 > AES_set_decrypt_key(key, BITS_SIZE, &m_decKey)) {
ThrowMsg(ResourceDecryptor::Exception::GetDecKeyFailed,
- "Failed to create decryption key");
+ "Failed to create decryption key");
}
- delete key;
}
AES_KEY* ResourceDecryptor::GetDecryptionKey()
}
void ResourceDecryptor::GetDecryptedChunk(unsigned char*
- inBuf, unsigned char* decBuf, size_t inBufSize)
+ inBuf,
+ unsigned char* decBuf,
+ size_t inBufSize)
{
Assert(decBuf);
if (decBuf == NULL) {
ThrowMsg(ResourceDecryptor::Exception::EncryptionFailed,
- "Failed to Get Decryption Chunk");
+ "Failed to Get Decryption Chunk");
}
- unsigned char ivec[16] = {0, };
+ unsigned char ivec[16] = { 0, };
AES_cbc_encrypt(inBuf, decBuf, inBufSize, &m_decKey, ivec, AES_DECRYPT);
LogDebug("Success decryption");
}
-
} //namespace WRTDecryptor