All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
Classes | Public Member Functions | Static Public Member Functions | List of all members
ndn::TpmPrivateKey Class Reference

A TpmPrivateKey holds an in-memory private key and provides cryptographic operations such as for signing by the in-memory TPM. More...

#include <tpm-private-key.hpp>

Classes

class  Error
 A TpmPrivateKey::Error extends runtime_error and represents an error in private key processing. More...
 

Public Member Functions

 TpmPrivateKey ()
 Create an uninitialized TpmPrivateKey. More...
 
void loadPkcs1 (const uint8_t *encoding, size_t encodingLength, KeyType keyType=(KeyType)-1)
 Load the unencrypted private key from a buffer with the PKCS #1 encoding. More...
 
void loadPkcs8 (const uint8_t *encoding, size_t encodingLength)
 Load the unencrypted private key from a buffer with the PKCS #8 encoding. More...
 
Blob derivePublicKey () const
 Get the encoded public key for this private key. More...
 
Blob decrypt (const uint8_t *cipherText, size_t cipherTextLength, ndn_EncryptAlgorithmType algorithmType=ndn_EncryptAlgorithmType_RsaOaep)
 Decrypt the cipherText using this private key according the encryption algorithmType. More...
 
Blob sign (const uint8_t *data, size_t dataLength, DigestAlgorithm digestAlgorithm)
 Sign the data with this private key, returning a signature Blob. More...
 
Blob toPkcs1 (bool includeParameters=true)
 Get the encoded unencrypted private key in PKCS #1. More...
 
Blob toPkcs8 (bool includeParameters=true)
 Get the encoded unencrypted private key in PKCS #8. More...
 

Static Public Member Functions

static ptr_lib::shared_ptr
< TpmPrivateKey
generatePrivateKey (const KeyParams &keyParams)
 Generate a key pair according to keyParams and return a new TpmPrivateKey with the private key. More...
 

Detailed Description

A TpmPrivateKey holds an in-memory private key and provides cryptographic operations such as for signing by the in-memory TPM.

Constructor & Destructor Documentation

ndn::TpmPrivateKey::TpmPrivateKey ( )
inline

Create an uninitialized TpmPrivateKey.

You must call a load method to initialize it, such as loadPkcs1.

Member Function Documentation

Blob ndn::TpmPrivateKey::decrypt ( const uint8_t *  cipherText,
size_t  cipherTextLength,
ndn_EncryptAlgorithmType  algorithmType = ndn_EncryptAlgorithmType_RsaOaep 
)

Decrypt the cipherText using this private key according the encryption algorithmType.

Only RSA encryption is supported for now.

Parameters
cipherTextThe cipher text byte array.
cipherTextLengthThe length of the cipher text byte array.
algorithmType(optional) This decrypts according to algorithmType. If omitted, use RsaOaep.
Returns
The decrypted data.
Exceptions
TpmPrivateKey::Errorif the private key is not loaded, if decryption is not supported for this key type, or for error decrypting.
Blob ndn::TpmPrivateKey::derivePublicKey ( ) const

Get the encoded public key for this private key.

Returns
The public key encoding Blob.
Exceptions
TpmPrivateKey::Errorif no private key is loaded, or error converting to a public key.
ptr_lib::shared_ptr< TpmPrivateKey > ndn::TpmPrivateKey::generatePrivateKey ( const KeyParams keyParams)
static

Generate a key pair according to keyParams and return a new TpmPrivateKey with the private key.

You can get the public key with derivePublicKey.

Parameters
keyParamsThe parameters of the key.
Returns
A new TpmPrivateKey.
Exceptions
std::invalid_argumentif the key type is not supported.
TpmPrivateKey::Errorfor an invalid key size, or an error generating.
void ndn::TpmPrivateKey::loadPkcs1 ( const uint8_t *  encoding,
size_t  encodingLength,
KeyType  keyType = (KeyType)-1 
)

Load the unencrypted private key from a buffer with the PKCS #1 encoding.

This replaces any existing private key in this object.

Parameters
encodingThe byte array with the private key encoding.
encodingLengthThe length of the encoding.
keyType(potional) The KeyType, such as KEY_TYPE_RSA. If omitted, then partially decode the private key to determine the key type.
Exceptions
TpmPrivateKey::Errorfor errors decoding the key.
void ndn::TpmPrivateKey::loadPkcs8 ( const uint8_t *  encoding,
size_t  encodingLength 
)

Load the unencrypted private key from a buffer with the PKCS #8 encoding.

This replaces any existing private key in this object.

Parameters
encodingThe byte array with the private key encoding.
encodingLengthThe length of the encoding.
Exceptions
TpmPrivateKey::Errorfor errors decoding the key.
Blob ndn::TpmPrivateKey::sign ( const uint8_t *  data,
size_t  dataLength,
DigestAlgorithm  digestAlgorithm 
)

Sign the data with this private key, returning a signature Blob.

Parameters
dataThe input byte array.
dataLengthThe length of the byte array.
digestAlgorithmthe digest algorithm.
Returns
The signature Blob, or an isNull Blob if this private key is not initialized.
Exceptions
TpmPrivateKey::Errorfor unrecognized digestAlgorithm or an error in signing.
Blob ndn::TpmPrivateKey::toPkcs1 ( bool  includeParameters = true)

Get the encoded unencrypted private key in PKCS #1.

Parameters
includeParameters(optional) If true and this is an EC key, then include the EC parameters in the encoding. If omitted, use true. Using false is deprecated.
Returns
The private key encoding Blob.
Exceptions
TpmPrivateKey::Errorif no private key is loaded, or error encoding.
Blob ndn::TpmPrivateKey::toPkcs8 ( bool  includeParameters = true)

Get the encoded unencrypted private key in PKCS #8.

Parameters
includeParameters(optional) If true and this is an EC key, then include the EC parameters in the encoding. If omitted, use true. Using false is deprecated.
Returns
The private key encoding Blob.
Exceptions
TpmPrivateKey::Errorif no private key is loaded, or error encoding.

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