7 #include "packager/media/base/aes_cryptor.h"
9 #include <openssl/aes.h>
11 #include "packager/base/logging.h"
12 #include "packager/base/stl_util.h"
14 namespace edash_packager {
17 AesCryptor::AesCryptor() : aes_key_(new AES_KEY) {}
18 AesCryptor::~AesCryptor() {}
20 bool AesCryptor::Crypt(
const std::vector<uint8_t>& text,
21 std::vector<uint8_t>* crypt_text) {
24 const size_t text_size = text.size();
25 crypt_text->resize(text_size + NumPaddingBytes(text_size));
26 size_t crypt_text_size = crypt_text->size();
27 if (!CryptInternal(text.data(), text_size, crypt_text->data(),
31 DCHECK_LE(crypt_text_size, crypt_text->size());
32 crypt_text->resize(crypt_text_size);
36 bool AesCryptor::Crypt(
const std::string& text, std::string* crypt_text) {
39 const size_t text_size = text.size();
40 crypt_text->resize(text_size + NumPaddingBytes(text_size));
41 size_t crypt_text_size = crypt_text->size();
42 if (!CryptInternal(reinterpret_cast<const uint8_t*>(text.data()), text_size,
43 reinterpret_cast<uint8_t*>(string_as_array(crypt_text)),
46 DCHECK_LE(crypt_text_size, crypt_text->size());
47 crypt_text->resize(crypt_text_size);
51 size_t AesCryptor::NumPaddingBytes(
size_t size)
const {