7 #include "packager/media/base/request_signer.h"
9 #include "packager/base/sha1.h"
10 #include "packager/base/strings/string_number_conversions.h"
11 #include "packager/media/base/aes_encryptor.h"
12 #include "packager/media/base/rsa_key.h"
14 namespace edash_packager {
17 RequestSigner::RequestSigner(
const std::string& signer_name)
18 : signer_name_(signer_name) {}
19 RequestSigner::~RequestSigner() {}
21 AesRequestSigner::AesRequestSigner(
const std::string& signer_name,
22 scoped_ptr<AesCbcPkcs5Encryptor> encryptor)
23 : RequestSigner(signer_name), aes_cbc_encryptor_(encryptor.Pass()) {
24 DCHECK(aes_cbc_encryptor_);
26 AesRequestSigner::~AesRequestSigner() {}
29 const std::string& aes_key_hex,
30 const std::string& iv_hex) {
31 std::vector<uint8_t> aes_key;
32 if (!base::HexStringToBytes(aes_key_hex, &aes_key)) {
33 LOG(ERROR) <<
"Failed to convert hex string to bytes: " << aes_key_hex;
36 std::vector<uint8_t> iv;
37 if (!base::HexStringToBytes(iv_hex, &iv)) {
38 LOG(ERROR) <<
"Failed to convert hex string to bytes: " << iv_hex;
43 if (!encryptor->InitializeWithIv(aes_key, iv))
49 std::string* signature) {
50 aes_cbc_encryptor_->Encrypt(base::SHA1HashString(message), signature);
54 RsaRequestSigner::RsaRequestSigner(
const std::string& signer_name,
55 scoped_ptr<RsaPrivateKey> rsa_private_key)
56 :
RequestSigner(signer_name), rsa_private_key_(rsa_private_key.Pass()) {
57 DCHECK(rsa_private_key_);
59 RsaRequestSigner::~RsaRequestSigner() {}
62 const std::string& signer_name,
63 const std::string& pkcs1_rsa_key) {
64 scoped_ptr<RsaPrivateKey> rsa_private_key(
72 std::string* signature) {
73 return rsa_private_key_->GenerateSignature(message, signature);