Virgil Security Crypto library  2.0.7
VirgilAsymmetricCipher.h
1 
37 #ifndef VIRGIL_CRYPTO_ASYMMETRIC_CIPHER_H
38 #define VIRGIL_CRYPTO_ASYMMETRIC_CIPHER_H
39 
40 #include <cstdlib>
41 #include <memory>
42 
43 #include <virgil/crypto/VirgilByteArray.h>
44 #include <virgil/crypto/VirgilKeyPair.h>
45 #include <virgil/crypto/foundation/asn1/VirgilAsn1Compatible.h>
46 
47 namespace virgil { namespace crypto { namespace foundation {
48 
53 public:
57 
67 
71 
76  size_t keySize() const;
77 
82  size_t keyLength() const;
84 
88 
98  static bool isKeyPairMatch(
99  const virgil::crypto::VirgilByteArray& publicKey,
100  const virgil::crypto::VirgilByteArray& privateKey,
102 
103 
112  static bool isPublicKeyValid(const virgil::crypto::VirgilByteArray& key);
113 
122  static void checkPublicKey(const virgil::crypto::VirgilByteArray& key);
123 
131  static bool checkPrivateKeyPassword(
134 
135 
142  static bool isPrivateKeyEncrypted(const virgil::crypto::VirgilByteArray& privateKey);
144 
148 
159  void setPrivateKey(
162 
172 
181  void genKeyPair(VirgilKeyPair::Type type);
182 
191  void genKeyPairFrom(const VirgilAsymmetricCipher& other);
192 
208  const VirgilAsymmetricCipher& publicContext,
209  const VirgilAsymmetricCipher& privateContext);
211 
215 
224 
231 
240 
248 
255 
262 
270 
282 
297 
301 
314 
328 
332 
345  virgil::crypto::VirgilByteArray sign(const virgil::crypto::VirgilByteArray& digest, int hashType) const;
346 
358  bool verify(
359  const virgil::crypto::VirgilByteArray& digest,
360  const virgil::crypto::VirgilByteArray& sign, int hashType) const;
362 
365  virtual size_t asn1Write(
368  size_t childWrittenBytes = 0) const override;
369 
370  virtual void asn1Read(virgil::crypto::foundation::asn1::VirgilAsn1Reader& asn1Reader) override;
372 public:
375 
376  VirgilAsymmetricCipher& operator=(VirgilAsymmetricCipher&& rhs) noexcept;
377 
378  virtual ~VirgilAsymmetricCipher() noexcept;
380 
381 private:
385  void checkState() const;
386 
387 private:
388  class Impl;
389 
390  std::unique_ptr<Impl> impl_;
391 };
392 
393 }}}
394 
395 #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.
This class provides methods for reading ASN.1 data structure.
Definition: VirgilAsn1Reader.h:53
Provides asymmetric ciphers algorithms (PK).
Definition: VirgilAsymmetricCipher.h:52
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
static bool isPublicKeyValid(const virgil::crypto::VirgilByteArray &key)
Check if given public key has a valid format.
virtual void asn1Read(virgil::crypto::foundation::asn1::VirgilAsn1Reader &asn1Reader) override
Read object state from the reader.
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.
Root namespace for all Virgil Security libraries.
Definition: VirgilAsn1Compatible.h:46
size_t keySize() const
Provides size in bits of the underlying key.
std::vector< unsigned char > VirgilByteArray
This type represents a sequence of bytes.
Definition: VirgilByteArray.h:53
virgil::crypto::VirgilKeyPair::Type getKeyType() const
Return type of the underlying key.
virtual size_t asn1Write(virgil::crypto::foundation::asn1::VirgilAsn1Writer &asn1Writer, size_t childWrittenBytes=0) const override
Write object state to the writer.
static bool isPrivateKeyEncrypted(const virgil::crypto::VirgilByteArray &privateKey)
Check if given private key is encrypted.
static void checkPublicKey(const virgil::crypto::VirgilByteArray &key)
Check if given public key has a valid format.
virgil::crypto::VirgilByteArray exportPublicKeyToPEM() const
Provides public key.
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.
void setKeyType(virgil::crypto::VirgilKeyPair::Type keyType)
Change type of the underlying key.