Virgil Security Crypto library  1.8.2
VirgilAsymmetricCipher.h
1 
37 #ifndef VIRGIL_CRYPTO_ASYMMETRIC_CIPHER_H
38 #define VIRGIL_CRYPTO_ASYMMETRIC_CIPHER_H
39 
40 #include <cstddef>
41 
42 #include <virgil/crypto/VirgilByteArray.h>
43 #include <virgil/crypto/VirgilKeyPair.h>
44 #include <virgil/crypto/foundation/asn1/VirgilAsn1Compatible.h>
45 
46 namespace virgil { namespace crypto { namespace foundation {
47 
51 class VirgilKeyPairGenerator;
53 
54 class VirgilAsymmetricCipherImpl;
56 
61 public:
65 
75 
79 
84  size_t keySize() const;
85 
90  size_t keyLength() const;
92 
96 
106  static bool isKeyPairMatch(
107  const virgil::crypto::VirgilByteArray& publicKey,
108  const virgil::crypto::VirgilByteArray& privateKey,
109  const virgil::crypto::VirgilByteArray& privateKeyPassword = virgil::crypto::VirgilByteArray());
110 
119  static bool checkPrivateKeyPassword(
120  const virgil::crypto::VirgilByteArray& key,
121  const virgil::crypto::VirgilByteArray& pwd);
122 
130  static bool isPrivateKeyEncrypted(const virgil::crypto::VirgilByteArray& privateKey);
132 
136 
144  void setPrivateKey(
145  const virgil::crypto::VirgilByteArray& key,
146  const virgil::crypto::VirgilByteArray& pwd = virgil::crypto::VirgilByteArray());
147 
154  void setPublicKey(const virgil::crypto::VirgilByteArray& key);
155 
162  void genKeyPair(VirgilKeyPair::Type type);
163 
170  void genKeyPairFrom(const VirgilAsymmetricCipher& other);
171 
180  static VirgilByteArray computeShared(
181  const VirgilAsymmetricCipher& publicContext,
182  const VirgilAsymmetricCipher& privateContext);
184 
188 
194  virgil::crypto::VirgilByteArray exportPrivateKeyToDER(
195  const virgil::crypto::VirgilByteArray& pwd = virgil::crypto::VirgilByteArray()) const;
196 
201  virgil::crypto::VirgilByteArray exportPublicKeyToDER() const;
202 
208  virgil::crypto::VirgilByteArray exportPrivateKeyToPEM(
209  const virgil::crypto::VirgilByteArray& pwd = virgil::crypto::VirgilByteArray()) const;
210 
215  virgil::crypto::VirgilByteArray exportPublicKeyToPEM() const;
217 
224 
230 
236 
245  virgil::crypto::VirgilByteArray getPublicKeyBits() const;
246 
255  void setPublicKeyBits(const virgil::crypto::VirgilByteArray& bits);
256 
265  virgil::crypto::VirgilByteArray signToBits(const virgil::crypto::VirgilByteArray& sign);
266 
275  virgil::crypto::VirgilByteArray signFromBits(const virgil::crypto::VirgilByteArray& bits);
277 
281 
291  virgil::crypto::VirgilByteArray encrypt(const virgil::crypto::VirgilByteArray& in) const;
292 
302  virgil::crypto::VirgilByteArray decrypt(const virgil::crypto::VirgilByteArray& in) const;
304 
308 
319  virgil::crypto::VirgilByteArray sign(const virgil::crypto::VirgilByteArray& digest, int hashType) const;
320 
332  bool verify(
333  const virgil::crypto::VirgilByteArray& digest,
334  const virgil::crypto::VirgilByteArray& sign, int hashType) const;
336 
344 
345  VirgilAsymmetricCipher& operator=(const VirgilAsymmetricCipher& rhs);
347 
350  virtual size_t asn1Write(
353  size_t childWrittenBytes = 0) const;
354 
357 private:
362  explicit VirgilAsymmetricCipher(int type);
363 
367  void checkState() const;
368 
369 public:
370  virtual ~VirgilAsymmetricCipher() throw();
371 
372 private:
373  VirgilAsymmetricCipherImpl* impl_;
374 };
375 
376 }}}
377 
378 #endif /* VIRGIL_CRYPTO_ASYMMETRIC_CIPHER_H */
virgil::crypto::VirgilByteArray exportPublicKeyToDER() const
Provides public key.
virgil::crypto::VirgilByteArray exportPrivateKeyToPEM(const virgil::crypto::VirgilByteArray &pwd=virgil::crypto::VirgilByteArray()) const
Provides private key.
virtual void asn1Read(virgil::crypto::foundation::asn1::VirgilAsn1Reader &asn1Reader)
Read object state from the reader.
This class provides methods for reading ASN.1 data structure.
Definition: VirgilAsn1Reader.h:53
Provides asymmetric ciphers algorithms (PK).
Definition: VirgilAsymmetricCipher.h:60
static VirgilByteArray computeShared(const VirgilAsymmetricCipher &publicContext, const VirgilAsymmetricCipher &privateContext)
Compute shared secret key on a given contexts.
This class provides interface that allow to save and restore object state in the ASN.1 structure.
Definition: VirgilAsn1Compatible.h:59
virgil::crypto::VirgilByteArray exportPrivateKeyToDER(const virgil::crypto::VirgilByteArray &pwd=virgil::crypto::VirgilByteArray()) const
Provides private key.
virgil::crypto::VirgilByteArray getPublicKeyBits() const
Return number of the underlying public key.
This class provides methods for writing ASN.1 data structure.
Definition: VirgilAsn1Writer.h:54
VirgilAsymmetricCipher()
Create object that is not initialized with specific algorithm yet.
Type
Type of the keypair.
Definition: VirgilKeyPair.h:52
void setPublicKeyBits(const virgil::crypto::VirgilByteArray &bits)
Set number of the underlying public key.
static bool isKeyPairMatch(const virgil::crypto::VirgilByteArray &publicKey, const virgil::crypto::VirgilByteArray &privateKey, const virgil::crypto::VirgilByteArray &privateKeyPassword=virgil::crypto::VirgilByteArray())
Check if a public-private pair of keys matches.
Definition: VirgilAsn1Compatible.h:46
size_t keySize() const
Provides size in bits of the underlying key.
virgil::crypto::VirgilKeyPair::Type getKeyType() const
Return type of the underlying key.
static bool isPrivateKeyEncrypted(const virgil::crypto::VirgilByteArray &privateKey)
Check if given private key is encrypted.
virgil::crypto::VirgilByteArray signToBits(const virgil::crypto::VirgilByteArray &sign)
Return number of the given sign.
virgil::crypto::VirgilByteArray exportPublicKeyToPEM() const
Provides public key.
virgil::crypto::VirgilByteArray signFromBits(const virgil::crypto::VirgilByteArray &bits)
Make sign from the given number.
virgil::crypto::VirgilByteArray sign(const virgil::crypto::VirgilByteArray &digest, int hashType) const
Sign given hash.
void genKeyPair(VirgilKeyPair::Type type)
Generates private and public keys.
void setPrivateKey(const virgil::crypto::VirgilByteArray &key, const virgil::crypto::VirgilByteArray &pwd=virgil::crypto::VirgilByteArray())
Configures private key.
void setPublicKey(const virgil::crypto::VirgilByteArray &key)
Configures public key.
bool verify(const virgil::crypto::VirgilByteArray &digest, const virgil::crypto::VirgilByteArray &sign, int hashType) const
Verify given hash with given sign.
void genKeyPairFrom(const VirgilAsymmetricCipher &other)
Generates private and public keys of the same type from the given context.
virgil::crypto::VirgilByteArray decrypt(const virgil::crypto::VirgilByteArray &in) const
Decrypts given message.
size_t keyLength() const
Provides the length in bytes of the underlying key.
virgil::crypto::VirgilByteArray encrypt(const virgil::crypto::VirgilByteArray &in) const
Encrypts given message.
static bool checkPrivateKeyPassword(const virgil::crypto::VirgilByteArray &key, const virgil::crypto::VirgilByteArray &pwd)
Check if given private key and it's password matches.
virtual size_t asn1Write(virgil::crypto::foundation::asn1::VirgilAsn1Writer &asn1Writer, size_t childWrittenBytes=0) const
Write object state to the writer.
void setKeyType(virgil::crypto::VirgilKeyPair::Type keyType)
Change type of the underlying key.