NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
ndn::security::transform::PrivateKey Class Reference

Abstraction of private key in crypto transformation. More...

#include <private-key.hpp>

Inheritance diagram for ndn::security::transform::PrivateKey:
Collaboration diagram for ndn::security::transform::PrivateKey:

Classes

class  Error
 

Public Types

typedef function< int(char *buf, size_t bufSize, bool shouldConfirm)> PasswordCallback
 Callback for application to handle password input. More...
 

Public Member Functions

 PrivateKey ()
 Create an empty private key instance. More...
 
 ~PrivateKey ()
 
KeyType getKeyType () const
 Get the type of the private key. More...
 
void loadPkcs1 (const uint8_t *buf, size_t size)
 Load the private key in PKCS#1 format from a buffer buf. More...
 
void loadPkcs1 (std::istream &is)
 Load the private key in PKCS#1 format from a stream is. More...
 
void loadPkcs1Base64 (const uint8_t *buf, size_t size)
 Load the private key in base64-encoded PKCS#1 format from a buffer buf. More...
 
void loadPkcs1Base64 (std::istream &is)
 Load the private key in base64-encoded PKCS#1 format from a stream is. More...
 
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. More...
 
void loadPkcs8 (const uint8_t *buf, size_t size, PasswordCallback pwCallback=nullptr)
 Load the private key in encrypted PKCS#8 format from a buffer buf with passphrase obtained from pwCallback. More...
 
void loadPkcs8 (std::istream &is, const char *pw, size_t pwLen)
 Load the private key in encrypted PKCS#8 format from a stream is with passphrase pw. More...
 
void loadPkcs8 (std::istream &is, PasswordCallback pwCallback=nullptr)
 Load the private key in encrypted PKCS#8 format from a stream is with passphrase obtained from pwCallback. More...
 
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. More...
 
void loadPkcs8Base64 (const uint8_t *buf, size_t size, PasswordCallback pwCallback=nullptr)
 Load the private key in encrypted PKCS#8 format from a buffer buf with passphrase obtained from pwCallback. More...
 
void loadPkcs8Base64 (std::istream &is, const char *pw, size_t pwLen)
 Load the private key in base64-encoded encrypted PKCS#8 format from a stream is with passphrase pw. More...
 
void loadPkcs8Base64 (std::istream &is, PasswordCallback pwCallback=nullptr)
 Load the private key in base64-encoded encrypted PKCS#8 format from a stream is with passphrase obtained from pwCallback. More...
 
void savePkcs1 (std::ostream &os) const
 Save the private key in PKCS#1 format into a stream os. More...
 
void savePkcs1Base64 (std::ostream &os) const
 Save the private key in base64-encoded PKCS#1 format into a stream os. More...
 
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. More...
 
void savePkcs8 (std::ostream &os, PasswordCallback pwCallback=nullptr) const
 Save the private key in encrypted PKCS#8 format into a stream os with passphrase obtained from pwCallback. More...
 
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. More...
 
void savePkcs8Base64 (std::ostream &os, PasswordCallback pwCallback=nullptr) const
 Save the private key in base64-encoded encrypted PKCS#8 format into a stream os with passphrase obtained from pwCallback. More...
 
ConstBufferPtr derivePublicKey () const
 
ConstBufferPtr decrypt (const uint8_t *cipherText, size_t cipherLen) const
 

Friends

class SignerFilter
 
unique_ptr< PrivateKeygeneratePrivateKey (const KeyParams &)
 Generate a private key according to keyParams. More...
 

Detailed Description

Abstraction of private key in crypto transformation.

Definition at line 38 of file private-key.hpp.

Member Typedef Documentation

typedef function<int(char* buf, size_t bufSize, bool shouldConfirm)> ndn::security::transform::PrivateKey::PasswordCallback

Callback for application to handle password input.

The password must be written to buf and must not be longer than bufSize chars. It is recommended to ask the user to verify the password if shouldConfirm is true, e.g., by prompting for it twice. The callback must return the number of characters in the password or 0 if an error occurred.

Definition at line 59 of file private-key.hpp.

Constructor & Destructor Documentation

ndn::security::transform::PrivateKey::PrivateKey ( )

Create an empty private key instance.

One must call loadXXXX(...) to load a private key.

Definition at line 80 of file private-key.cpp.

References ~PrivateKey().

ndn::security::transform::PrivateKey::~PrivateKey ( )
default

Referenced by PrivateKey().

Member Function Documentation

KeyType ndn::security::transform::PrivateKey::getKeyType ( ) const

Get the type of the private key.

Definition at line 88 of file private-key.cpp.

References ndn::EC, ndn::security::detail::getEvpPkeyType(), ndn::NONE, and ndn::RSA.

Referenced by ndn::security::transform::SignerFilter::SignerFilter().

void ndn::security::transform::PrivateKey::loadPkcs1 ( const uint8_t *  buf,
size_t  size 
)

Load the private key in PKCS#1 format from a buffer buf.

Definition at line 104 of file private-key.cpp.

References ENSURE_PRIVATE_KEY_NOT_LOADED, and ndn::security::transform::opensslInitAlgorithms().

Referenced by ndn::security::tpm::BackEndOsx::derivePublicKey(), loadPkcs1(), and loadPkcs1Base64().

void ndn::security::transform::PrivateKey::loadPkcs1 ( std::istream &  is)

Load the private key in PKCS#1 format from a stream is.

Definition at line 114 of file private-key.cpp.

References ndn::OBufferStream::buf(), loadPkcs1(), and ndn::security::transform::streamSink().

void ndn::security::transform::PrivateKey::loadPkcs1Base64 ( const uint8_t *  buf,
size_t  size 
)

Load the private key in base64-encoded PKCS#1 format from a buffer buf.

Definition at line 122 of file private-key.cpp.

References ndn::security::transform::base64Decode(), ndn::OBufferStream::buf(), loadPkcs1(), and ndn::security::transform::streamSink().

void ndn::security::transform::PrivateKey::loadPkcs1Base64 ( std::istream &  is)

Load the private key in base64-encoded PKCS#1 format from a stream is.

Definition at line 130 of file private-key.cpp.

References ndn::security::transform::base64Decode(), ndn::OBufferStream::buf(), loadPkcs1(), and ndn::security::transform::streamSink().

void ndn::security::transform::PrivateKey::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.

Precondition
strlen(pw) == pwLen

Definition at line 138 of file private-key.cpp.

References ENSURE_PRIVATE_KEY_NOT_LOADED, ndn::security::transform::opensslInitAlgorithms(), and ndn::security::detail::Bio::write().

Referenced by loadPkcs8(), and loadPkcs8Base64().

void ndn::security::transform::PrivateKey::loadPkcs8 ( const uint8_t *  buf,
size_t  size,
PasswordCallback  pwCallback = nullptr 
)

Load the private key in encrypted PKCS#8 format from a buffer buf with passphrase obtained from pwCallback.

The default password callback is provided by OpenSSL

Definition at line 161 of file private-key.cpp.

References ENSURE_PRIVATE_KEY_NOT_LOADED, ndn::security::transform::opensslInitAlgorithms(), ndn::security::transform::passwordCallbackWrapper(), and ndn::security::detail::Bio::write().

void ndn::security::transform::PrivateKey::loadPkcs8 ( std::istream &  is,
const char *  pw,
size_t  pwLen 
)

Load the private key in encrypted PKCS#8 format from a stream is with passphrase pw.

Precondition
strlen(pw) == pwLen

Definition at line 180 of file private-key.cpp.

References ndn::OBufferStream::buf(), loadPkcs8(), and ndn::security::transform::streamSink().

void ndn::security::transform::PrivateKey::loadPkcs8 ( std::istream &  is,
PasswordCallback  pwCallback = nullptr 
)

Load the private key in encrypted PKCS#8 format from a stream is with passphrase obtained from pwCallback.

The default password callback is provided by OpenSSL

Definition at line 188 of file private-key.cpp.

References ndn::OBufferStream::buf(), loadPkcs8(), and ndn::security::transform::streamSink().

void ndn::security::transform::PrivateKey::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.

Precondition
strlen(pw) == pwLen

Definition at line 196 of file private-key.cpp.

References ndn::security::transform::base64Decode(), ndn::OBufferStream::buf(), loadPkcs8(), and ndn::security::transform::streamSink().

void ndn::security::transform::PrivateKey::loadPkcs8Base64 ( const uint8_t *  buf,
size_t  size,
PasswordCallback  pwCallback = nullptr 
)

Load the private key in encrypted PKCS#8 format from a buffer buf with passphrase obtained from pwCallback.

The default password callback is provided by OpenSSL

Definition at line 204 of file private-key.cpp.

References ndn::security::transform::base64Decode(), ndn::OBufferStream::buf(), loadPkcs8(), and ndn::security::transform::streamSink().

void ndn::security::transform::PrivateKey::loadPkcs8Base64 ( std::istream &  is,
const char *  pw,
size_t  pwLen 
)

Load the private key in base64-encoded encrypted PKCS#8 format from a stream is with passphrase pw.

Precondition
strlen(pw) == pwLen

Definition at line 212 of file private-key.cpp.

References ndn::security::transform::base64Decode(), ndn::OBufferStream::buf(), loadPkcs8(), and ndn::security::transform::streamSink().

void ndn::security::transform::PrivateKey::loadPkcs8Base64 ( std::istream &  is,
PasswordCallback  pwCallback = nullptr 
)

Load the private key in base64-encoded encrypted PKCS#8 format from a stream is with passphrase obtained from pwCallback.

The default password callback is provided by OpenSSL

Definition at line 220 of file private-key.cpp.

References ndn::security::transform::base64Decode(), ndn::OBufferStream::buf(), loadPkcs8(), and ndn::security::transform::streamSink().

void ndn::security::transform::PrivateKey::savePkcs1 ( std::ostream &  os) const

Save the private key in PKCS#1 format into a stream os.

Definition at line 228 of file private-key.cpp.

References ndn::security::transform::streamSink().

void ndn::security::transform::PrivateKey::savePkcs1Base64 ( std::ostream &  os) const

Save the private key in base64-encoded PKCS#1 format into a stream os.

Definition at line 234 of file private-key.cpp.

References ndn::security::transform::base64Encode(), and ndn::security::transform::streamSink().

void ndn::security::transform::PrivateKey::savePkcs8 ( std::ostream &  os,
const char *  pw,
size_t  pwLen 
) const

Save the private key in encrypted PKCS#8 format into a stream os.

Definition at line 240 of file private-key.cpp.

References ndn::security::transform::streamSink().

void ndn::security::transform::PrivateKey::savePkcs8 ( std::ostream &  os,
PasswordCallback  pwCallback = nullptr 
) const

Save the private key in encrypted PKCS#8 format into a stream os with passphrase obtained from pwCallback.

The default password callback is provided by OpenSSL

Definition at line 246 of file private-key.cpp.

References ndn::security::transform::streamSink().

void ndn::security::transform::PrivateKey::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.

Definition at line 252 of file private-key.cpp.

References ndn::security::transform::base64Encode(), and ndn::security::transform::streamSink().

void ndn::security::transform::PrivateKey::savePkcs8Base64 ( std::ostream &  os,
PasswordCallback  pwCallback = nullptr 
) const

Save the private key in base64-encoded encrypted PKCS#8 format into a stream os with passphrase obtained from pwCallback.

The default password callback is provided by OpenSSL

Definition at line 258 of file private-key.cpp.

References ndn::security::transform::base64Encode(), and ndn::security::transform::streamSink().

ConstBufferPtr ndn::security::transform::PrivateKey::derivePublicKey ( ) const
Returns
Public key bits in PKCS#8 format

Definition at line 264 of file private-key.cpp.

References ENSURE_PRIVATE_KEY_LOADED.

Referenced by ndn::security::tpm::BackEndOsx::derivePublicKey().

ConstBufferPtr ndn::security::transform::PrivateKey::decrypt ( const uint8_t *  cipherText,
size_t  cipherLen 
) const
Returns
Plain text of cipherText decrypted using this private key.

Only RSA encryption is supported for now.

Definition at line 280 of file private-key.cpp.

References ENSURE_PRIVATE_KEY_LOADED, ndn::security::detail::getEvpPkeyType(), ndn::security::transform::opensslInitAlgorithms(), ndn::security::transform::passwordCallbackWrapper(), ndn::security::detail::Bio::read(), and ndn::to_string().

Friends And Related Function Documentation

friend class SignerFilter
friend

Definition at line 224 of file private-key.hpp.

unique_ptr<PrivateKey> generatePrivateKey ( const KeyParams )
friend

Generate a private key according to keyParams.

Note
The public key can be derived from the private key.
Exceptions
std::invalid_argumentthe specified key type is not supported
std::runtime_errorkey generation fails

Definition at line 432 of file private-key.cpp.


The documentation for this class was generated from the following files: