NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
private-key.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #ifndef NDN_CXX_SECURITY_TRANSFORM_PRIVATE_KEY_HPP
23 #define NDN_CXX_SECURITY_TRANSFORM_PRIVATE_KEY_HPP
24 
25 #include "public-key.hpp"
26 #include "../../encoding/buffer.hpp"
27 
28 namespace ndn {
29 
30 class KeyParams;
31 
32 namespace security {
33 namespace transform {
34 
38 class PrivateKey : noncopyable
39 {
40 public:
41  class Error : public std::runtime_error
42  {
43  public:
44  explicit
45  Error(const std::string& what)
46  : std::runtime_error(what)
47  {
48  }
49  };
50 
51  friend class SignerFilter;
52 
60  typedef function<int(char* buf, size_t bufSize, bool shouldConfirm)> PasswordCallback;
61 
62 public:
68  PrivateKey();
69 
70  ~PrivateKey();
71 
75  void
76  loadPkcs1(const uint8_t* buf, size_t size);
77 
81  void
82  loadPkcs1(std::istream& is);
83 
87  void
88  loadPkcs1Base64(const uint8_t* buf, size_t size);
89 
93  void
94  loadPkcs1Base64(std::istream& is);
95 
101  void
102  loadPkcs8(const uint8_t* buf, size_t size, const char* pw, size_t pwLen);
103 
110  void
111  loadPkcs8(const uint8_t* buf, size_t size, PasswordCallback pwCallback = nullptr);
112 
118  void
119  loadPkcs8(std::istream& is, const char* pw, size_t pwLen);
120 
127  void
128  loadPkcs8(std::istream& is, PasswordCallback pwCallback = nullptr);
129 
136  void
137  loadPkcs8Base64(const uint8_t* buf, size_t size, const char* pw, size_t pwLen);
138 
145  void
146  loadPkcs8Base64(const uint8_t* buf, size_t size, PasswordCallback pwCallback = nullptr);
147 
154  void
155  loadPkcs8Base64(std::istream& is, const char* pw, size_t pwLen);
156 
163  void
164  loadPkcs8Base64(std::istream& is, PasswordCallback pwCallback = nullptr);
165 
169  void
170  savePkcs1(std::ostream& os) const;
171 
175  void
176  savePkcs1Base64(std::ostream& os) const;
177 
181  void
182  savePkcs8(std::ostream& os, const char* pw, size_t pwLen) const;
183 
190  void
191  savePkcs8(std::ostream& os, PasswordCallback pwCallback = nullptr) const;
192 
196  void
197  savePkcs8Base64(std::ostream& os, const char* pw, size_t pwLen) const;
198 
205  void
206  savePkcs8Base64(std::ostream& os, PasswordCallback pwCallback = nullptr) const;
207 
212  derivePublicKey() const;
213 
220  decrypt(const uint8_t* cipherText, size_t cipherLen) const;
221 
222 private:
228  void*
229  getEvpPkey() const;
230 
231 private:
233  toPkcs1() const;
234 
236  toPkcs8(const char* pw, size_t pwLen) const;
237 
239  toPkcs8(PasswordCallback pwCallback = nullptr) const;
240 
242  rsaDecrypt(const uint8_t* cipherText, size_t cipherLen) const;
243 
244 private:
245  class Impl;
246  unique_ptr<Impl> m_impl;
247 };
248 
257 unique_ptr<PrivateKey>
258 generatePrivateKey(const KeyParams& keyParams);
259 
260 } // namespace transform
261 } // namespace security
262 } // namespace ndn
263 
264 #endif // NDN_CXX_SECURITY_TRANSFORM_PRIVATE_KEY_HPP
Copyright (c) 2011-2015 Regents of the University of California.
void loadPkcs8(const uint8_t *buf, size_t size, const char *pw, size_t pwLen)
Load the private key in encrypted PKCS#8 format from a buffer buf with passphrase pw...
void loadPkcs1Base64(const uint8_t *buf, size_t size)
Load the private key in base64-encoded PKCS#1 format from a buffer buf.
Definition: private-key.cpp:88
function< int(char *buf, size_t bufSize, bool shouldConfirm)> PasswordCallback
Callback for application to handle password input.
Definition: private-key.hpp:60
void loadPkcs1(const uint8_t *buf, size_t size)
Load the private key in PKCS#1 format from a buffer buf.
Definition: private-key.cpp:69
STL namespace.
void savePkcs8(std::ostream &os, const char *pw, size_t pwLen) const
Save the private key in encrypted PKCS#8 format into a stream os.
void savePkcs8Base64(std::ostream &os, const char *pw, size_t pwLen) const
Save the private key in base64-encoded encrypted PKCS#8 format into a stream os.
unique_ptr< PrivateKey > generatePrivateKey(const KeyParams &keyParams)
generate a private key according to keyParams.
PrivateKey()
Create a private key instance.
Definition: private-key.cpp:61
void loadPkcs8Base64(const uint8_t *buf, size_t size, const char *pw, size_t pwLen)
Load the private key in base64-encoded encrypted PKCS#8 format from a buffer buf with passphrase pw...
ConstBufferPtr decrypt(const uint8_t *cipherText, size_t cipherLen) const
Abstraction of private key in crypto transformation.
Definition: private-key.hpp:38
Base class of key parameters.
Definition: key-params.hpp:35
ConstBufferPtr derivePublicKey() const
shared_ptr< const Buffer > ConstBufferPtr
Definition: buffer.hpp:33
void savePkcs1Base64(std::ostream &os) const
Save the private key in base64-encoded PKCS#1 format into a stream os.
void savePkcs1(std::ostream &os) const
Save the private key in PKCS#1 format into a stream os.