Public Member Functions | Static Protected Member Functions | List of all members
ndn::PrivateKeyStorage Class Referenceabstract
Inheritance diagram for ndn::PrivateKeyStorage:
ndn::FilePrivateKeyStorage ndn::MemoryPrivateKeyStorage

Public Member Functions

virtual ~PrivateKeyStorage ()
 The virtual destructor.
 
virtual void generateKeyPair (const Name &keyName, const KeyParams &params)=0
 Generate a pair of asymmetric keys. More...
 
virtual void deleteKeyPair (const Name &keyName)=0
 Delete a pair of asymmetric keys. More...
 
virtual ptr_lib::shared_ptr< PublicKeygetPublicKey (const Name &keyName)=0
 Get the public key. More...
 
virtual Blob sign (const uint8_t *data, size_t dataLength, const Name &keyName, DigestAlgorithm digestAlgorithm=DIGEST_ALGORITHM_SHA256)=0
 Fetch the private key for keyName and sign the data, returning a signature Blob. More...
 
Blob sign (const Blob &data, const Name &keyName, DigestAlgorithm digestAlgorithm=DIGEST_ALGORITHM_SHA256)
 
virtual Blob decrypt (const Name &keyName, const uint8_t *data, size_t dataLength, bool isSymmetric=false)=0
 Decrypt data. More...
 
Blob decrypt (const Name &keyName, const Blob &data, bool isSymmetric=false)
 
virtual Blob encrypt (const Name &keyName, const uint8_t *data, size_t dataLength, bool isSymmetric=false)=0
 Encrypt data. More...
 
Blob encrypt (const Name &keyName, const Blob &data, bool isSymmetric=false)
 
virtual void generateKey (const Name &keyName, const KeyParams &params)=0
 Generate a symmetric key. More...
 
virtual bool doesKeyExist (const Name &keyName, KeyClass keyClass)=0
 Check if a particular key exists. More...
 

Static Protected Member Functions

static Blob encodePkcs8PrivateKey (const std::vector< uint8_t > &privateKeyDer, const OID &oid, const ptr_lib::shared_ptr< DerNode > &parameters)
 Encode the private key to a PKCS #8 private key. More...
 
static Blob encodeSubjectPublicKeyInfo (const OID &oid, const ptr_lib::shared_ptr< DerNode > &parameters, const ptr_lib::shared_ptr< DerNode > &bitString)
 Encode the bitString into a SubjectPublicKeyInfo. More...
 
static ec_key_st * decodeEcPrivateKey (const ptr_lib::shared_ptr< DerNode > &algorithmParameters, const Blob &privateKeyDer)
 Create an EC key using the curve in the algorithmParameters, decode the privateKeyDer and set the private key value. More...
 

Member Function Documentation

static ec_key_st* ndn::PrivateKeyStorage::decodeEcPrivateKey ( const ptr_lib::shared_ptr< DerNode > &  algorithmParameters,
const Blob privateKeyDer 
)
staticprotected

Create an EC key using the curve in the algorithmParameters, decode the privateKeyDer and set the private key value.

This is necessary because d2i_ECPrivateKey does not seem to work with the "parameterless" private key encoding produced by NFD.

Parameters
algorithmParametersThe parameters from the PKCS #8 AlgorithmIdentifier.
privateKeyDerThe bytes of the inner PKCS #8 private key.
Returns
A new ec_key_st. You must call EC_KEY_free.
Exceptions
SecurityExceptionif can't decode the private key.
virtual Blob ndn::PrivateKeyStorage::decrypt ( const Name keyName,
const uint8_t *  data,
size_t  dataLength,
bool  isSymmetric = false 
)
pure virtual

Decrypt data.

Parameters
keyNameThe name of the decrypting key.
dataThe byte to be decrypted.
dataLengththe length of data.
isSymmetricIf true symmetric encryption is used, otherwise asymmetric encryption is used.
Returns
The decrypted data.

Implemented in ndn::MemoryPrivateKeyStorage, and ndn::FilePrivateKeyStorage.

virtual void ndn::PrivateKeyStorage::deleteKeyPair ( const Name keyName)
pure virtual

Delete a pair of asymmetric keys.

If the key doesn't exist, do nothing.

Parameters
keyNameThe name of the key pair.

Implemented in ndn::MemoryPrivateKeyStorage, and ndn::FilePrivateKeyStorage.

virtual bool ndn::PrivateKeyStorage::doesKeyExist ( const Name keyName,
KeyClass  keyClass 
)
pure virtual

Check if a particular key exists.

Parameters
keyNameThe name of the key.
keyClassThe class of the key, e.g. KEY_CLASS_PUBLIC, KEY_CLASS_PRIVATE, or KEY_CLASS_SYMMETRIC.
Returns
True if the key exists, otherwise false.

Implemented in ndn::MemoryPrivateKeyStorage, and ndn::FilePrivateKeyStorage.

Blob ndn::PrivateKeyStorage::encodePkcs8PrivateKey ( const std::vector< uint8_t > &  privateKeyDer,
const OID oid,
const ptr_lib::shared_ptr< DerNode > &  parameters 
)
staticprotected

Encode the private key to a PKCS #8 private key.

We do this explicitly here to avoid linking to extra OpenSSL libraries.

Parameters
privateKeyDerThe input private key DER.
oidThe OID of the privateKey.
parametersThe DerNode of the parameters for the OID.
Returns
The PKCS #8 private key DER.
Blob ndn::PrivateKeyStorage::encodeSubjectPublicKeyInfo ( const OID oid,
const ptr_lib::shared_ptr< DerNode > &  parameters,
const ptr_lib::shared_ptr< DerNode > &  bitString 
)
staticprotected

Encode the bitString into a SubjectPublicKeyInfo.

Parameters
oidThe OID of the privateKey.
parametersThe DerNode of the parameters for the OID.
bitstringThe public key bitString which is already in a DerNode::DerBitString.
Returns
The subject public key info DER.
virtual Blob ndn::PrivateKeyStorage::encrypt ( const Name keyName,
const uint8_t *  data,
size_t  dataLength,
bool  isSymmetric = false 
)
pure virtual

Encrypt data.

Parameters
keyNameThe name of the encrypting key.
dataThe byte to be encrypted.
dataLengththe length of data.
isSymmetricIf true symmetric encryption is used, otherwise asymmetric encryption is used.
Returns
The encrypted data.

Implemented in ndn::MemoryPrivateKeyStorage, and ndn::FilePrivateKeyStorage.

virtual void ndn::PrivateKeyStorage::generateKey ( const Name keyName,
const KeyParams params 
)
pure virtual

Generate a symmetric key.

Parameters
keyNameThe name of the key.
paramsThe parameters of the key.

Implemented in ndn::MemoryPrivateKeyStorage, and ndn::FilePrivateKeyStorage.

virtual void ndn::PrivateKeyStorage::generateKeyPair ( const Name keyName,
const KeyParams params 
)
pure virtual

Generate a pair of asymmetric keys.

Parameters
keyNameThe name of the key pair.
paramsThe parameters of the key.

Implemented in ndn::MemoryPrivateKeyStorage, and ndn::FilePrivateKeyStorage.

virtual ptr_lib::shared_ptr<PublicKey> ndn::PrivateKeyStorage::getPublicKey ( const Name keyName)
pure virtual

Get the public key.

Parameters
keyNameThe name of public key.
Returns
The public key.

Implemented in ndn::MemoryPrivateKeyStorage, and ndn::FilePrivateKeyStorage.

virtual Blob ndn::PrivateKeyStorage::sign ( const uint8_t *  data,
size_t  dataLength,
const Name keyName,
DigestAlgorithm  digestAlgorithm = DIGEST_ALGORITHM_SHA256 
)
pure virtual

Fetch the private key for keyName and sign the data, returning a signature Blob.

Parameters
dataPointer to the input byte array.
dataLengthThe length of data.
keyNameThe name of the signing key.
digestAlgorithmthe digest algorithm.
Returns
The signature Blob.

Implemented in ndn::MemoryPrivateKeyStorage, and ndn::FilePrivateKeyStorage.


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