Shaka Packager SDK
rsa_key.h
1 // Copyright 2014 Google LLC. All rights reserved.
2 //
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file or at
5 // https://developers.google.com/open-source/licenses/bsd
6 //
7 // Declaration of classes representing RSA private and public keys used
8 // for message signing, signature verification, encryption and decryption.
9 
10 #ifndef PACKAGER_MEDIA_BASE_RSA_KEY_H_
11 #define PACKAGER_MEDIA_BASE_RSA_KEY_H_
12 
13 #include <string>
14 
15 #include <mbedtls/ctr_drbg.h>
16 #include <mbedtls/entropy.h>
17 #include <mbedtls/pk.h>
18 
19 #include <packager/macros/classes.h>
20 
21 namespace shaka {
22 namespace media {
23 
26  public:
27  ~RsaPrivateKey();
28 
31  static RsaPrivateKey* Create(const std::string& serialized_key);
32 
36  bool Decrypt(const std::string& encrypted_message,
37  std::string* decrypted_message);
38 
42  bool GenerateSignature(const std::string& message, std::string* signature);
43 
44  private:
45  RsaPrivateKey();
46 
47  bool Deserialize(const std::string& serialized_key);
48 
49  mbedtls_pk_context pk_context_;
50  mbedtls_entropy_context entropy_context_;
51  mbedtls_ctr_drbg_context prng_context_;
52 
53  DISALLOW_COPY_AND_ASSIGN(RsaPrivateKey);
54 };
55 
57 class RsaPublicKey {
58  public:
59  ~RsaPublicKey();
60 
63  static RsaPublicKey* Create(const std::string& serialized_key);
64 
68  bool Encrypt(const std::string& clear_message,
69  std::string* encrypted_message);
70 
73  bool VerifySignature(const std::string& message,
74  const std::string& signature);
75 
76  private:
77  RsaPublicKey();
78 
79  bool Deserialize(const std::string& serialized_key);
80 
81  mbedtls_pk_context pk_context_;
82  mbedtls_entropy_context entropy_context_;
83  mbedtls_ctr_drbg_context prng_context_;
84 
85  DISALLOW_COPY_AND_ASSIGN(RsaPublicKey);
86 };
87 
88 } // namespace media
89 } // namespace shaka
90 
91 #endif // PACKAGER_MEDIA_BASE_RSA_KEY_H_
Rsa private key, used for message signing and decryption.
Definition: rsa_key.h:25
bool Decrypt(const std::string &encrypted_message, std::string *decrypted_message)
Definition: rsa_key.cc:118
bool GenerateSignature(const std::string &message, std::string *signature)
Definition: rsa_key.cc:149
static RsaPrivateKey * Create(const std::string &serialized_key)
Definition: rsa_key.cc:78
Rsa public key, used for signature verification and encryption.
Definition: rsa_key.h:57
bool VerifySignature(const std::string &message, const std::string &signature)
Definition: rsa_key.cc:253
static RsaPublicKey * Create(const std::string &serialized_key)
Definition: rsa_key.cc:188
bool Encrypt(const std::string &clear_message, std::string *encrypted_message)
Definition: rsa_key.cc:226
All the methods that are virtual are virtual for mocking.
Definition: crypto_flags.cc:66