private-key-storage.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
23 #ifndef NDN_PRIVATE_KEY_STORAGE_HPP
24 #define NDN_PRIVATE_KEY_STORAGE_HPP
25 
26 #include <string>
27 #include "../../encoding/oid.hpp"
28 #include "../../util/blob.hpp"
29 #include "../certificate/public-key.hpp"
30 #include "../security-common.hpp"
31 #include "../key-params.hpp"
32 #include "../../name.hpp"
33 #include "../../lite/security/ec-private-key-lite.hpp"
34 
35 namespace ndn {
36 
37 class DerNode;
38 
40 public:
44  virtual
46 
52  virtual void
53  generateKeyPair(const Name& keyName, const KeyParams& params) = 0;
54 
59  virtual void
60  deleteKeyPair(const Name& keyName) = 0;
61 
67  virtual ptr_lib::shared_ptr<PublicKey>
68  getPublicKey(const Name& keyName) = 0;
69 
78  virtual Blob
79  sign(const uint8_t *data, size_t dataLength, const Name& keyName, DigestAlgorithm digestAlgorithm = DIGEST_ALGORITHM_SHA256) = 0;
80 
81  Blob
82  sign(const Blob& data, const Name& keyName, DigestAlgorithm digestAlgorithm = DIGEST_ALGORITHM_SHA256)
83  {
84  return sign(data.buf(), data.size(), keyName, digestAlgorithm);
85  }
86 
95  virtual Blob
96  decrypt(const Name& keyName, const uint8_t* data, size_t dataLength, bool isSymmetric = false) = 0;
97 
98  Blob
99  decrypt(const Name& keyName, const Blob& data, bool isSymmetric = false)
100  {
101  return decrypt(keyName, data.buf(), data.size(), isSymmetric);
102  }
103 
112  virtual Blob
113  encrypt(const Name& keyName, const uint8_t* data, size_t dataLength, bool isSymmetric = false) = 0;
114 
115  Blob
116  encrypt(const Name& keyName, const Blob& data, bool isSymmetric = false)
117  {
118  return encrypt(keyName, data.buf(), data.size(), isSymmetric);
119  }
120 
126  virtual void
127  generateKey(const Name& keyName, const KeyParams& params) = 0;
128 
135  virtual bool
136  doesKeyExist(const Name& keyName, KeyClass keyClass) = 0;
137 
146  static Blob
148  (const std::vector<uint8_t>& privateKeyDer, const OID& oid,
149  const ptr_lib::shared_ptr<DerNode>& parameters);
150 
159  static Blob
161  (const OID& oid, const ptr_lib::shared_ptr<DerNode>& parameters,
162  const ptr_lib::shared_ptr<DerNode>& bitString);
163 
164 protected:
175  void
177  (const ptr_lib::shared_ptr<DerNode>& algorithmParameters,
178  const Blob& privateKeyDer, EcPrivateKeyLite& privateKey);
179 };
180 
181 }
182 
183 #endif
Copyright (C) 2013-2016 Regents of the University of California.
Definition: common.hpp:36
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.
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.
Definition: private-key-storage.cpp:55
virtual void deleteKeyPair(const Name &keyName)=0
Delete a pair of asymmetric keys.
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.
Definition: private-key-storage.cpp:37
virtual void generateKeyPair(const Name &keyName, const KeyParams &params)=0
Generate a pair of asymmetric keys.
virtual Blob encrypt(const Name &keyName, const uint8_t *data, size_t dataLength, bool isSymmetric=false)=0
Encrypt data.
virtual void generateKey(const Name &keyName, const KeyParams &params)=0
Generate a symmetric key.
A Name holds an array of Name::Component and represents an NDN name.
Definition: name.hpp:40
virtual Blob decrypt(const Name &keyName, const uint8_t *data, size_t dataLength, bool isSymmetric=false)=0
Decrypt data.
A Blob holds a pointer to an immutable byte array implemented as const std::vector.
Definition: blob.hpp:42
An EcPrivateKeyLite holds a decoded or generated EC private key for use in crypto operations...
Definition: ec-private-key-lite.hpp:35
const uint8_t * buf() const
Return a const pointer to the first byte of the immutable byte array, or 0 if the pointer is null...
Definition: blob.hpp:159
size_t size() const
Return the length of the immutable byte array.
Definition: blob.hpp:147
KeyParams is a base class for key parameters.
Definition: key-params.hpp:35
void decodeEcPrivateKey(const ptr_lib::shared_ptr< DerNode > &algorithmParameters, const Blob &privateKeyDer, EcPrivateKeyLite &privateKey)
Set the EC key using the curve in the algorithmParameters, decode the privateKeyDer and set the priva...
virtual ptr_lib::shared_ptr< PublicKey > getPublicKey(const Name &keyName)=0
Get the public key.
Definition: oid.hpp:31
virtual ~PrivateKeyStorage()
The virtual destructor.
Definition: private-key-storage.cpp:33
virtual bool doesKeyExist(const Name &keyName, KeyClass keyClass)=0
Check if a particular key exists.
Definition: private-key-storage.hpp:39