[Release] wrt-commons_0.2.139
[framework/web/wrt-commons.git] / modules / encryption / src / resource_decryption.cpp
index 9e8b39f..c599e64 100644 (file)
 #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(std::string userKey) 
+ResourceDecryptor::ResourceDecryptor(std::string userKey)
 {
     LogDebug("Finished Decryption");
     SetDecryptionKey(userKey);
 }
 
 ResourceDecryptor::~ResourceDecryptor()
-{
-}
+{}
 
 void ResourceDecryptor::SetDecryptionKey(std::string userKey)
 {
@@ -53,12 +53,14 @@ void ResourceDecryptor::SetDecryptionKey(std::string userKey)
         return;
     }
 
-    char **duk = calculate(const_cast<char*>(userKey.c_str()), userKey.size(), KEY_SIZE);
-    unsigned char *key = reinterpret_cast<unsigned char*>(*duk);
+    char* pKey = GetDeviceUniqueKey(const_cast<char*>(userKey.c_str()),
+            userKey.size(), KEY_SIZE);
 
-    if ( 0 > AES_set_decrypt_key(key, BITS_SIZE, &m_decKey)) {
+    unsigned char *key = reinterpret_cast<unsigned char*>(pKey);
+
+    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");
     }
 }
 
@@ -68,17 +70,18 @@ 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