2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * @file resource_decryption.cpp
18 * @author Soyoung Kim (sy037.kim@samsung.com)
20 * @brief Implementation file for resource decryption
23 #include <dpl/encryption/resource_decryption.h>
27 #include <dpl/log/log.h>
28 #include <dpl/exception.h>
34 namespace WRTDecryptor {
35 ResourceDecryptor::ResourceDecryptor()
37 LogDebug("Started Decryption");
40 ResourceDecryptor::ResourceDecryptor(std::string userKey)
42 LogDebug("Finished Decryption");
43 SetDecryptionKey(userKey);
46 ResourceDecryptor::~ResourceDecryptor()
49 void ResourceDecryptor::SetDecryptionKey(std::string userKey)
51 if (userKey.empty()) {
55 char **duk = calculate(const_cast<char*>(userKey.c_str()),
56 userKey.size(), KEY_SIZE);
57 unsigned char *key = reinterpret_cast<unsigned char*>(*duk);
59 if (0 > AES_set_decrypt_key(key, BITS_SIZE, &m_decKey)) {
60 ThrowMsg(ResourceDecryptor::Exception::GetDecKeyFailed,
61 "Failed to create decryption key");
65 AES_KEY* ResourceDecryptor::GetDecryptionKey()
70 void ResourceDecryptor::GetDecryptedChunk(unsigned char*
72 unsigned char* decBuf,
77 ThrowMsg(ResourceDecryptor::Exception::EncryptionFailed,
78 "Failed to Get Decryption Chunk");
80 unsigned char ivec[16] = { 0, };
82 AES_cbc_encrypt(inBuf, decBuf, inBufSize, &m_decKey, ivec, AES_DECRYPT);
83 LogDebug("Success decryption");
85 } //namespace WRTDecryptor