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 
34 struct ec_key_st;
35 
36 namespace ndn {
37 
38 class DerNode;
39 
41 public:
45  virtual
47 
53  virtual void
54  generateKeyPair(const Name& keyName, const KeyParams& params) = 0;
55 
60  virtual void
61  deleteKeyPair(const Name& keyName) = 0;
62 
68  virtual ptr_lib::shared_ptr<PublicKey>
69  getPublicKey(const Name& keyName) = 0;
70 
79  virtual Blob
80  sign(const uint8_t *data, size_t dataLength, const Name& keyName, DigestAlgorithm digestAlgorithm = DIGEST_ALGORITHM_SHA256) = 0;
81 
82  Blob
83  sign(const Blob& data, const Name& keyName, DigestAlgorithm digestAlgorithm = DIGEST_ALGORITHM_SHA256)
84  {
85  return sign(data.buf(), data.size(), keyName, digestAlgorithm);
86  }
87 
96  virtual Blob
97  decrypt(const Name& keyName, const uint8_t* data, size_t dataLength, bool isSymmetric = false) = 0;
98 
99  Blob
100  decrypt(const Name& keyName, const Blob& data, bool isSymmetric = false)
101  {
102  return decrypt(keyName, data.buf(), data.size(), isSymmetric);
103  }
104 
113  virtual Blob
114  encrypt(const Name& keyName, const uint8_t* data, size_t dataLength, bool isSymmetric = false) = 0;
115 
116  Blob
117  encrypt(const Name& keyName, const Blob& data, bool isSymmetric = false)
118  {
119  return encrypt(keyName, data.buf(), data.size(), isSymmetric);
120  }
121 
127  virtual void
128  generateKey(const Name& keyName, const KeyParams& params) = 0;
129 
136  virtual bool
137  doesKeyExist(const Name& keyName, KeyClass keyClass) = 0;
138 
139 protected:
148  static Blob
150  (const std::vector<uint8_t>& privateKeyDer, const OID& oid,
151  const ptr_lib::shared_ptr<DerNode>& parameters);
152 
161  static Blob
163  (const OID& oid, const ptr_lib::shared_ptr<DerNode>& parameters,
164  const ptr_lib::shared_ptr<DerNode>& bitString);
165 
176  static ec_key_st*
178  (const ptr_lib::shared_ptr<DerNode>& algorithmParameters,
179  const Blob& privateKeyDer);
180 };
181 
182 }
183 
184 #endif
Copyright (C) 2013-2016 Regents of the University of California.
Definition: common.hpp:35
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:56
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 pri...
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:38
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.
virtual ~PrivateKeyStorage()
The virtual destructor.
Definition: private-key-storage.hpp:46
A Blob holds a pointer to an immutable byte array implemented as const std::vector.
Definition: blob.hpp:42
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:34
virtual ptr_lib::shared_ptr< PublicKey > getPublicKey(const Name &keyName)=0
Get the public key.
virtual bool doesKeyExist(const Name &keyName, KeyClass keyClass)=0
Check if a particular key exists.
Definition: private-key-storage.hpp:40