DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
rsa_key.h
1 // Copyright 2014 Google Inc. 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 MEDIA_BASE_RSA_KEY_H_
11 #define MEDIA_BASE_RSA_KEY_H_
12 
13 #include <string>
14 
15 #include "packager/base/macros.h"
16 
17 struct rsa_st;
18 typedef struct rsa_st RSA;
19 
20 namespace shaka {
21 namespace media {
22 
25  public:
26  ~RsaPrivateKey();
27 
30  static RsaPrivateKey* Create(const std::string& serialized_key);
31 
35  bool Decrypt(const std::string& encrypted_message,
36  std::string* decrypted_message);
37 
41  bool GenerateSignature(const std::string& message, std::string* signature);
42 
43  private:
44  // RsaPrivateKey takes owership of |rsa_key|.
45  explicit RsaPrivateKey(RSA* rsa_key);
46 
47  RSA* rsa_key_; // owned
48 
49  DISALLOW_COPY_AND_ASSIGN(RsaPrivateKey);
50 };
51 
53 class RsaPublicKey {
54  public:
55  ~RsaPublicKey();
56 
59  static RsaPublicKey* Create(const std::string& serialized_key);
60 
64  bool Encrypt(const std::string& clear_message,
65  std::string* encrypted_message);
66 
69  bool VerifySignature(const std::string& message,
70  const std::string& signature);
71 
72  private:
73  // RsaPublicKey takes owership of |rsa_key|.
74  explicit RsaPublicKey(RSA* rsa_key);
75 
76  RSA* rsa_key_; // owned
77 
78  DISALLOW_COPY_AND_ASSIGN(RsaPublicKey);
79 };
80 
81 } // namespace media
82 } // namespace shaka
83 
84 #endif // MEDIA_BASE_RSA_KEY_H_
Rsa public key, used for signature verification and encryption.
Definition: rsa_key.h:53
bool Encrypt(const std::string &clear_message, std::string *encrypted_message)
Definition: rsa_key.cc:176
bool Decrypt(const std::string &encrypted_message, std::string *decrypted_message)
Definition: rsa_key.cc:101
Rsa private key, used for message signing and decryption.
Definition: rsa_key.h:24
bool VerifySignature(const std::string &message, const std::string &signature)
Definition: rsa_key.cc:200
static RsaPublicKey * Create(const std::string &serialized_key)
Definition: rsa_key.cc:171
bool GenerateSignature(const std::string &message, std::string *signature)
Definition: rsa_key.cc:127
static RsaPrivateKey * Create(const std::string &serialized_key)
Definition: rsa_key.cc:96