Virgil Security Crypto library  2.6.3
VirgilKeyPair.h
1 
37 #ifndef VIRGIL_KEY_PAIR_H
38 #define VIRGIL_KEY_PAIR_H
39 
40 #include "VirgilByteArray.h"
41 
42 namespace virgil { namespace crypto {
43 
48 public:
78  enum class Type {
79  RSA_256,
80  RSA_512,
81  RSA_1024,
82  RSA_2048,
83  RSA_3072,
84  RSA_4096,
85  RSA_8192,
86  EC_SECP192R1,
87  EC_SECP224R1,
88  EC_SECP256R1,
89  EC_SECP384R1,
90  EC_SECP521R1,
91  EC_BP256R1,
92  EC_BP384R1,
93  EC_BP512R1,
94  EC_SECP192K1,
95  EC_SECP224K1,
96  EC_SECP256K1,
100  };
104  using Algorithm = Type;
105 public:
111  static VirgilKeyPair generate(
112  VirgilKeyPair::Type type,
113  const VirgilByteArray& pwd = VirgilByteArray());
114 
120  const VirgilByteArray& pwd = VirgilByteArray());
121 
129  const VirgilKeyPair& donorKeyPair,
130  const VirgilByteArray& donorPrivateKeyPassword = VirgilByteArray(),
131  const VirgilByteArray& newKeyPairPassword = VirgilByteArray());
132 
144  VirgilKeyPair::Type type,
145  const VirgilByteArray& keyMaterial,
146  const VirgilByteArray& pwd = VirgilByteArray());
160  const VirgilByteArray& keyMaterial,
161  const VirgilByteArray& pwd = VirgilByteArray());
162 
166 
176  static bool isKeyPairMatch(
177  const VirgilByteArray& publicKey,
179  const VirgilByteArray& privateKeyPassword = VirgilByteArray());
180 
189  static bool checkPrivateKeyPassword(
190  const VirgilByteArray& key,
191  const VirgilByteArray& pwd);
192 
200  static bool isPrivateKeyEncrypted(const VirgilByteArray& privateKey);
202 
205 
218  const VirgilByteArray& privateKey,
219  const VirgilByteArray& oldPassword, const VirgilByteArray& newPassword);
220 
236  const VirgilByteArray& privateKey,
237  const VirgilByteArray& privateKeyPassword);
238 
255  const VirgilByteArray& privateKey,
256  const VirgilByteArray& privateKeyPassword);
257 
267  const VirgilByteArray& privateKey,
268  const VirgilByteArray& privateKeyPassword);
269 
277  static VirgilByteArray publicKeyToPEM(const VirgilByteArray& publicKey);
278 
286  static VirgilByteArray publicKeyToDER(const VirgilByteArray& publicKey);
287 
298  const VirgilByteArray& privateKey,
299  const VirgilByteArray& privateKeyPassword = VirgilByteArray());
310  const VirgilByteArray& privateKey,
311  const VirgilByteArray& privateKeyPassword = VirgilByteArray());
313 
317  VirgilKeyPair(const VirgilByteArray& publicKey, const VirgilByteArray& privateKey);
318 
322  VirgilByteArray publicKey() const;
323 
327  VirgilByteArray privateKey() const;
328 
329 private:
330  VirgilByteArray publicKey_;
331  VirgilByteArray privateKey_;
332 };
333 
334 }}
335 
336 #endif /* VIRGIL_KEY_PAIR_H */
static bool isPrivateKeyEncrypted(const VirgilByteArray &privateKey)
Check if given private key is encrypted.
Curve25519 as ECP deprecated format.
static VirgilKeyPair generate(VirgilKeyPair::Type type, const VirgilByteArray &pwd=VirgilByteArray())
Generate new key pair given type.
static bool checkPrivateKeyPassword(const VirgilByteArray &key, const VirgilByteArray &pwd)
Check if given private key and it's password matches.
static VirgilKeyPair generateRecommendedFromKeyMaterial(const VirgilByteArray &keyMaterial, const VirgilByteArray &pwd=VirgilByteArray())
Generates recommended private and public keys from the given key material.
Type
Specific key algorithm type.
Definition: VirgilKeyPair.h:78
static VirgilByteArray privateKeyToDER(const VirgilByteArray &privateKey, const VirgilByteArray &privateKeyPassword=VirgilByteArray())
Convert given private key to the DER format.
static VirgilKeyPair generateFromKeyMaterial(VirgilKeyPair::Type type, const VirgilByteArray &keyMaterial, const VirgilByteArray &pwd=VirgilByteArray())
Generates private and public keys from the given key material.
Root namespace for all Virgil Security libraries.
Definition: VirgilAsn1Compatible.h:46
std::vector< unsigned char > VirgilByteArray
This type represents a sequence of bytes.
Definition: VirgilByteArray.h:50
static bool isKeyPairMatch(const VirgilByteArray &publicKey, const VirgilByteArray &privateKey, const VirgilByteArray &privateKeyPassword=VirgilByteArray())
Check if a public-private pair of keys matches.
static VirgilByteArray publicKeyToDER(const VirgilByteArray &publicKey)
Convert given public key to the DER format.
This class handles information about Virgil Security key pair.
Definition: VirgilKeyPair.h:47
static VirgilByteArray extractPublicKey(const VirgilByteArray &privateKey, const VirgilByteArray &privateKeyPassword)
Extract public key from the private key.
static VirgilByteArray publicKeyToPEM(const VirgilByteArray &publicKey)
Convert given public key to the PEM format.
static VirgilByteArray decryptPrivateKey(const VirgilByteArray &privateKey, const VirgilByteArray &privateKeyPassword)
Return plain (non encrypted) private key.
static VirgilKeyPair generateFrom(const VirgilKeyPair &donorKeyPair, const VirgilByteArray &donorPrivateKeyPassword=VirgilByteArray(), const VirgilByteArray &newKeyPairPassword=VirgilByteArray())
Generate new key pair of the same type based on the donor key pair.
static VirgilByteArray encryptPrivateKey(const VirgilByteArray &privateKey, const VirgilByteArray &privateKeyPassword)
Return encrypted private key in PKCS#8 format.
VirgilKeyPair(const VirgilByteArray &publicKey, const VirgilByteArray &privateKey)
Initialize key pair with given public and private key.
static VirgilByteArray privateKeyToPEM(const VirgilByteArray &privateKey, const VirgilByteArray &privateKeyPassword=VirgilByteArray())
Convert given private key to the PEM format.
static VirgilByteArray resetPrivateKeyPassword(const VirgilByteArray &privateKey, const VirgilByteArray &oldPassword, const VirgilByteArray &newPassword)
Reset password for the given private key.
static VirgilKeyPair generateRecommended(const VirgilByteArray &pwd=VirgilByteArray())
Generate new key pair with recommended most safe type.
VirgilByteArray publicKey() const
Provide access to the public key.
VirgilByteArray privateKey() const
Provide access to the private key.