7 #include "packager/media/base/request_signer.h"
9 #include "packager/base/logging.h"
10 #include "packager/base/sha1.h"
11 #include "packager/base/strings/string_number_conversions.h"
12 #include "packager/media/base/aes_encryptor.h"
13 #include "packager/media/base/rsa_key.h"
18 RequestSigner::RequestSigner(
const std::string& signer_name)
19 : signer_name_(signer_name) {}
20 RequestSigner::~RequestSigner() {}
22 AesRequestSigner::AesRequestSigner(
const std::string& signer_name,
23 std::unique_ptr<AesCbcEncryptor> encryptor)
24 : RequestSigner(signer_name), aes_cbc_encryptor_(std::move(encryptor)) {
25 DCHECK(aes_cbc_encryptor_);
27 AesRequestSigner::~AesRequestSigner() {}
30 const std::string& aes_key_hex,
31 const std::string& iv_hex) {
32 std::vector<uint8_t> aes_key;
33 if (!base::HexStringToBytes(aes_key_hex, &aes_key)) {
34 LOG(ERROR) <<
"Failed to convert hex string to bytes: " << aes_key_hex;
37 std::vector<uint8_t> iv;
38 if (!base::HexStringToBytes(iv_hex, &iv)) {
39 LOG(ERROR) <<
"Failed to convert hex string to bytes: " << iv_hex;
43 std::unique_ptr<AesCbcEncryptor> encryptor(
45 if (!encryptor->InitializeWithIv(aes_key, iv))
51 std::string* signature) {
52 aes_cbc_encryptor_->Crypt(base::SHA1HashString(message), signature);
56 RsaRequestSigner::RsaRequestSigner(
57 const std::string& signer_name,
58 std::unique_ptr<RsaPrivateKey> rsa_private_key)
59 :
RequestSigner(signer_name), rsa_private_key_(std::move(rsa_private_key)) {
60 DCHECK(rsa_private_key_);
62 RsaRequestSigner::~RsaRequestSigner() {}
65 const std::string& signer_name,
66 const std::string& pkcs1_rsa_key) {
67 std::unique_ptr<RsaPrivateKey> rsa_private_key(
75 std::string* signature) {
76 return rsa_private_key_->GenerateSignature(message, signature);