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_encryption.cpp
18 * @author Soyoung Kim (sy037.kim@samsung.com)
20 * @brief Implementation file for resource encryption
23 #include <dpl/encryption/resource_encryption.h>
26 #include <dpl/log/log.h>
33 namespace WRTEncryptor {
34 ResourceEncryptor::ResourceEncryptor()
36 LogDebug("Started Encrytion");
39 ResourceEncryptor::~ResourceEncryptor()
41 LogDebug("Finished Encrytion");
44 int ResourceEncryptor::GetBlockSize(int inSize)
46 if ((inSize % AES_BLOCK_SIZE) != 0) {
47 return (( inSize / AES_BLOCK_SIZE) + 1) * AES_BLOCK_SIZE;
52 void ResourceEncryptor::CreateEncryptionKey(std::string userKey)
54 if (userKey.empty()) {
58 char* pKey = GetDeviceUniqueKey(const_cast<char*>(userKey.c_str()),
59 userKey.size(), KEY_SIZE);
60 unsigned char *key = reinterpret_cast<unsigned char*>(pKey);
62 if (0 > AES_set_encrypt_key(key, BITS_SIZE, &m_encKey)) {
63 ThrowMsg(ResourceEncryptor::Exception::CreateEncKeyFailed,
64 "Failed to create encryption key");
66 LogDebug("Success to create ecryption and decryption key");
69 AES_KEY ResourceEncryptor::GetEncryptionkey()
74 void ResourceEncryptor::EncryptChunk(unsigned char*
76 unsigned char* encBuf,
82 unsigned char ivec[16] = { 0, };
84 AES_cbc_encrypt(inputBuf, encBuf, chunkSize, &m_encKey, ivec, AES_ENCRYPT);
86 } //namespace ResourceEnc