37 #ifndef VIRGIL_CRYPTO_ASYMMETRIC_CIPHER_H 38 #define VIRGIL_CRYPTO_ASYMMETRIC_CIPHER_H 43 #include "../VirgilByteArray.h" 44 #include "../VirgilKeyPair.h" 45 #include "asn1/VirgilAsn1Compatible.h" 47 namespace virgil {
namespace crypto {
namespace foundation {
385 size_t childWrittenBytes = 0)
const override;
402 void checkState()
const;
404 size_t calculateExportedPublicKeySizeMaxDER()
const;
405 size_t calculateExportedPublicKeySizeMaxPEM()
const;
406 size_t calculateExportedPrivateKeySizeMaxDER(
size_t encryptionOverhead)
const;
407 size_t calculateExportedPrivateKeySizeMaxPEM(
size_t encryptionOverhead)
const;
415 std::unique_ptr<Impl> 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.
This class provides methods for reading ASN.1 data structure.
Definition: VirgilAsn1Reader.h:53
virtual size_t asn1Write(virgil::crypto::foundation::asn1::VirgilAsn1Writer &asn1Writer, size_t childWrittenBytes=0) const override
Write object state to the writer.
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
Specific key algorithm type.
Definition: VirgilKeyPair.h:78
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.
void genKeyPairFromKeyMaterial(VirgilKeyPair::Type type, const VirgilByteArray &keyMaterial)
Generates private and public keys from the given key material.
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:50
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.
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.