37 #ifndef VIRGIL_CRYPTO_ASYMMETRIC_CIPHER_H
38 #define VIRGIL_CRYPTO_ASYMMETRIC_CIPHER_H
42 #include <virgil/crypto/VirgilByteArray.h>
43 #include <virgil/crypto/VirgilKeyPair.h>
44 #include <virgil/crypto/foundation/asn1/VirgilAsn1Compatible.h>
46 namespace virgil {
namespace crypto {
namespace foundation {
51 class VirgilKeyPairGenerator;
54 class VirgilAsymmetricCipherImpl;
107 const virgil::crypto::VirgilByteArray& publicKey,
108 const virgil::crypto::VirgilByteArray& privateKey,
109 const virgil::crypto::VirgilByteArray& privateKeyPassword = virgil::crypto::VirgilByteArray());
120 const virgil::crypto::VirgilByteArray& key,
121 const virgil::crypto::VirgilByteArray& pwd);
145 const virgil::crypto::VirgilByteArray& key,
146 const virgil::crypto::VirgilByteArray& pwd = virgil::crypto::VirgilByteArray());
154 void setPublicKey(
const virgil::crypto::VirgilByteArray& key);
195 const virgil::crypto::VirgilByteArray& pwd = virgil::crypto::VirgilByteArray())
const;
209 const virgil::crypto::VirgilByteArray& pwd = virgil::crypto::VirgilByteArray())
const;
265 virgil::crypto::VirgilByteArray
signToBits(
const virgil::crypto::VirgilByteArray&
sign);
275 virgil::crypto::VirgilByteArray
signFromBits(
const virgil::crypto::VirgilByteArray& bits);
291 virgil::crypto::VirgilByteArray
encrypt(
const virgil::crypto::VirgilByteArray& in)
const;
302 virgil::crypto::VirgilByteArray
decrypt(
const virgil::crypto::VirgilByteArray& in)
const;
319 virgil::crypto::VirgilByteArray
sign(
const virgil::crypto::VirgilByteArray& digest,
int hashType)
const;
333 const virgil::crypto::VirgilByteArray& digest,
334 const virgil::crypto::VirgilByteArray& sign,
int hashType)
const;
353 size_t childWrittenBytes = 0)
const;
367 void checkState()
const;
373 VirgilAsymmetricCipherImpl* impl_;
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.