file-private-key-storage.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
23 #ifndef NDN_FILE_PRIVATE_KEY_STORAGE_HPP
24 #define NDN_FILE_PRIVATE_KEY_STORAGE_HPP
25 
26 #include <string>
27 #include <ndn-cpp/encoding/oid.hpp>
28 #include "private-key-storage.hpp"
29 
30 struct ec_key_st;
31 
32 namespace ndn {
33 
34 class DerNode;
35 
41 public:
46 
50  virtual
52 
58  virtual void
59  generateKeyPair(const Name& keyName, const KeyParams& params);
60 
65  virtual void
66  deleteKeyPair(const Name& keyName);
67 
73  virtual ptr_lib::shared_ptr<PublicKey>
74  getPublicKey(const Name& keyName);
75 
84  virtual Blob
85  sign(const uint8_t *data, size_t dataLength, const Name& keyName, DigestAlgorithm digestAlgorithm = DIGEST_ALGORITHM_SHA256);
86 
95  virtual Blob
96  decrypt(const Name& keyName, const uint8_t* data, size_t dataLength, bool isSymmetric = false);
97 
106  virtual Blob
107  encrypt(const Name& keyName, const uint8_t* data, size_t dataLength, bool isSymmetric = false);
108 
114  virtual void
115  generateKey(const Name& keyName, const KeyParams& params);
116 
123  virtual bool
124  doesKeyExist(const Name& keyName, KeyClass keyClass);
125 
126 private:
127  std::string
128  nameTransform(const std::string& keyName, const std::string& extension);
129 
138  static Blob
139  encodePkcs8PrivateKey
140  (const std::vector<uint8_t>& privateKeyDer, const OID& oid,
141  const ptr_lib::shared_ptr<DerNode>& parameters);
142 
151  static Blob
152  encodeSubjectPublicKeyInfo
153  (const OID& oid, const ptr_lib::shared_ptr<DerNode>& parameters,
154  const ptr_lib::shared_ptr<DerNode>& bitString);
155 
166  static ec_key_st*
167  decodeEcPrivateKey
168  (const ptr_lib::shared_ptr<DerNode>& algorithmParameters,
169  const Blob& privateKeyDer);
170 
171  std::string keyStorePath_;
172 };
173 
174 }
175 
176 #endif
virtual Blob decrypt(const Name &keyName, const uint8_t *data, size_t dataLength, bool isSymmetric=false)
Decrypt data.
Definition: file-private-key-storage.cpp:356
Copyright (C) 2013-2015 Regents of the University of California.
Definition: common.hpp:35
FilePrivateKeyStorage extends PrivateKeyStorage to implement private key storage using files...
Definition: file-private-key-storage.hpp:40
virtual ~FilePrivateKeyStorage()
The virtual Destructor.
Definition: file-private-key-storage.cpp:135
virtual void generateKey(const Name &keyName, const KeyParams &params)
Generate a symmetric key.
Definition: file-private-key-storage.cpp:375
A Name holds an array of Name::Component and represents an NDN name.
Definition: name.hpp:42
virtual bool doesKeyExist(const Name &keyName, KeyClass keyClass)
Check if a particular key exists.
Definition: file-private-key-storage.cpp:383
A Blob holds a pointer to an immutable byte array implemented as const std::vector.
Definition: blob.hpp:42
virtual ptr_lib::shared_ptr< PublicKey > getPublicKey(const Name &keyName)
Get the public key.
Definition: file-private-key-storage.cpp:258
virtual void generateKeyPair(const Name &keyName, const KeyParams &params)
Generate a pair of asymmetric keys.
Definition: file-private-key-storage.cpp:141
virtual Blob encrypt(const Name &keyName, const uint8_t *data, size_t dataLength, bool isSymmetric=false)
Encrypt data.
Definition: file-private-key-storage.cpp:366
KeyParams is a base class for key parameters.
Definition: key-params.hpp:34
FilePrivateKeyStorage()
Create a new FilePrivateKeyStorage to connect to the default directory.
Definition: file-private-key-storage.cpp:116
Definition: oid.hpp:31
virtual void deleteKeyPair(const Name &keyName)
Delete a pair of asymmetric keys.
Definition: file-private-key-storage.cpp:249
Definition: private-key-storage.hpp:35
virtual Blob sign(const uint8_t *data, size_t dataLength, const Name &keyName, DigestAlgorithm digestAlgorithm=DIGEST_ALGORITHM_SHA256)
Fetch the private key for keyName and sign the data, returning a signature Blob.
Definition: file-private-key-storage.cpp:279