Virgil Security C++ SDK
Public Member Functions | List of all members
virgil::sdk::crypto::Crypto Class Reference

Class for high level interactions with crypto library. More...

#include <Crypto.h>

Public Member Functions

 Crypto (bool useSHA256Fingerprints=false)
 Constructor. More...
 
keys::KeyPair generateKeyPair () const
 Generates KeyPair of default key type. More...
 
keys::PrivateKey importPrivateKey (const VirgilByteArray &data, const std::string &password="") const
 Imports private key from raw data in DER or PEM format. More...
 
keys::PublicKey importPublicKey (const VirgilByteArray &data) const
 Imports public key from DER or PEM format. More...
 
keys::PublicKey extractPublicKeyFromPrivateKey (const keys::PrivateKey &privateKey) const
 Extracts public key from private key. More...
 
VirgilByteArray exportPrivateKey (const keys::PrivateKey &privateKey, const std::string &password="") const
 Exports encrypted using password private key. More...
 
VirgilByteArray exportPublicKey (const keys::PublicKey &publicKey) const
 Exports public key in DER format. More...
 
VirgilByteArray encrypt (const VirgilByteArray &data, const std::vector< keys::PublicKey > &recipients) const
 Encrypts data for passed PublicKeys. More...
 
void encrypt (std::istream &istream, std::ostream &ostream, const std::vector< keys::PublicKey > &recipients) const
 Encrypts data stream for passed PublicKeys. More...
 
bool verify (const VirgilByteArray &data, const VirgilByteArray &signature, const keys::PublicKey &signerPublicKey) const
 Verifies digital signature of data. More...
 
bool verify (std::istream &istream, const VirgilByteArray &signature, const keys::PublicKey &signerPublicKey) const
 Verifies digital signature of data stream. More...
 
VirgilByteArray decrypt (const VirgilByteArray &data, const keys::PrivateKey &privateKey) const
 Decrypts data using passed PrivateKey. More...
 
void decrypt (std::istream &istream, std::ostream &ostream, const keys::PrivateKey &privateKey) const
 Decrypts data stream using passed PrivateKey. More...
 
VirgilByteArray signThenEncrypt (const VirgilByteArray &data, const keys::PrivateKey &privateKey, const std::vector< keys::PublicKey > &recipients) const
 Signs (with private key) Then Encrypts data for passed PublicKeys. More...
 
VirgilByteArray decryptThenVerify (const VirgilByteArray &data, const keys::PrivateKey &privateKey, const keys::PublicKey &signerPublicKey) const
 Decrypts (with private key) Then Verifies data using signer PublicKey. More...
 
VirgilByteArray decryptThenVerify (const VirgilByteArray &data, const keys::PrivateKey &privateKey, const std::vector< keys::PublicKey > &signersPublicKeys) const
 Decrypts (with private key) Then Verifies data using any of signers' PublicKeys. More...
 
VirgilByteArray generateSignature (const VirgilByteArray &data, const keys::PrivateKey &privateKey) const
 Generates digital signature of data using private key. More...
 
VirgilByteArray generateSignature (std::istream &istream, const keys::PrivateKey &privateKey) const
 Generates digital signature of data stream using private key. More...
 
VirgilByteArray generateSHA512 (const VirgilByteArray &data) const
 Computes SHA-512. More...
 
VirgilByteArray computeHash (const VirgilByteArray &data, VirgilHashAlgorithm algorithm) const
 Computes hash of data using selected algorithm. More...
 
bool useSHA256Fingerprints () const
 Getter. More...
 

Detailed Description

Class for high level interactions with crypto library.

Constructor & Destructor Documentation

virgil::sdk::crypto::Crypto::Crypto ( bool  useSHA256Fingerprints = false)

Constructor.

Parameters
useSHA256Fingerprintsuse old algorithm to generate key fingerprints
Note
Current algorithm: first 8 bytes of SHA512 of public key in DER format. Old algorithm SHA256 of public key in DER format. Use SHA256 fingerprint only if you need to work with encrypted data, that was encrypted using those fingerprint.

Member Function Documentation

VirgilByteArray virgil::sdk::crypto::Crypto::computeHash ( const VirgilByteArray &  data,
VirgilHashAlgorithm  algorithm 
) const

Computes hash of data using selected algorithm.

Parameters
datadata of which hash is computed
algorithmhash algorithm
Returns
hash
VirgilByteArray virgil::sdk::crypto::Crypto::decrypt ( const VirgilByteArray &  data,
const keys::PrivateKey privateKey 
) const

Decrypts data using passed PrivateKey.

Parameters
dataencrypted data
privateKeyrecipient's private key
Returns
decrypted data
void virgil::sdk::crypto::Crypto::decrypt ( std::istream &  istream,
std::ostream &  ostream,
const keys::PrivateKey privateKey 
) const

Decrypts data stream using passed PrivateKey.

Parameters
istreamstream with encrypted data
ostreamstream with decrypted data
privateKeyrecipient's private key
VirgilByteArray virgil::sdk::crypto::Crypto::decryptThenVerify ( const VirgilByteArray &  data,
const keys::PrivateKey privateKey,
const keys::PublicKey signerPublicKey 
) const

Decrypts (with private key) Then Verifies data using signer PublicKey.

Parameters
datadata to be signed, then verified
privateKeyreceiver's private key
signerPublicKeysigner public key
Returns
decrypted, then verified data
VirgilByteArray virgil::sdk::crypto::Crypto::decryptThenVerify ( const VirgilByteArray &  data,
const keys::PrivateKey privateKey,
const std::vector< keys::PublicKey > &  signersPublicKeys 
) const

Decrypts (with private key) Then Verifies data using any of signers' PublicKeys.

Parameters
datadata to be signed, then verified
privateKeyreceiver's private key
signerPublicKeysigner public key
Returns
decrypted, then verified data
VirgilByteArray virgil::sdk::crypto::Crypto::encrypt ( const VirgilByteArray &  data,
const std::vector< keys::PublicKey > &  recipients 
) const

Encrypts data for passed PublicKeys.

Parameters
datadata to be encrypted
recipientsstd::vector with recipient's Public Keys
Returns
encrypted data
void virgil::sdk::crypto::Crypto::encrypt ( std::istream &  istream,
std::ostream &  ostream,
const std::vector< keys::PublicKey > &  recipients 
) const

Encrypts data stream for passed PublicKeys.

Parameters
istreamstream to be encrypted
ostreamstream with encrypted data
recipientsstd::vector with recipient's Public Keys
VirgilByteArray virgil::sdk::crypto::Crypto::exportPrivateKey ( const keys::PrivateKey privateKey,
const std::string &  password = "" 
) const

Exports encrypted using password private key.

Parameters
privateKeyPrivateKey to export
passwordPassword
Returns
exported encrypted private key
VirgilByteArray virgil::sdk::crypto::Crypto::exportPublicKey ( const keys::PublicKey publicKey) const

Exports public key in DER format.

Parameters
publicKeyPublicKey to export
Returns
exported public key in DER format
keys::PublicKey virgil::sdk::crypto::Crypto::extractPublicKeyFromPrivateKey ( const keys::PrivateKey privateKey) const

Extracts public key from private key.

Parameters
privateKeyPrivate key to extract from
Returns
Public Key that matches passed Private Key
keys::KeyPair virgil::sdk::crypto::Crypto::generateKeyPair ( ) const

Generates KeyPair of default key type.

Returns
generated KeyPair
VirgilByteArray virgil::sdk::crypto::Crypto::generateSHA512 ( const VirgilByteArray &  data) const

Computes SHA-512.

Parameters
datadata to be hashed
Returns
hash
VirgilByteArray virgil::sdk::crypto::Crypto::generateSignature ( const VirgilByteArray &  data,
const keys::PrivateKey privateKey 
) const

Generates digital signature of data using private key.

Parameters
datadata to sign
privateKeyPrivate Key to be used to generate signature
Returns
digital signature
VirgilByteArray virgil::sdk::crypto::Crypto::generateSignature ( std::istream &  istream,
const keys::PrivateKey privateKey 
) const

Generates digital signature of data stream using private key.

Parameters
istreamdata stream to sign
privateKeyPrivate Key to be used to generate signature
Returns
digital signature
keys::PrivateKey virgil::sdk::crypto::Crypto::importPrivateKey ( const VirgilByteArray &  data,
const std::string &  password = "" 
) const

Imports private key from raw data in DER or PEM format.

Parameters
dataPrivate Key in DER or PEM format
passwordpassword, if password is encrypted
Returns
keys::PublicKey virgil::sdk::crypto::Crypto::importPublicKey ( const VirgilByteArray &  data) const

Imports public key from DER or PEM format.

Parameters
dataPublic Key in DER or PEM format
Returns
imported Public Key
VirgilByteArray virgil::sdk::crypto::Crypto::signThenEncrypt ( const VirgilByteArray &  data,
const keys::PrivateKey privateKey,
const std::vector< keys::PublicKey > &  recipients 
) const

Signs (with private key) Then Encrypts data for passed PublicKeys.

Parameters
datadata to be signed, then encrypted
privateKeysender private key
recipientsstd::vector with recipient's Public Keys
Returns
signed, then encrypted data
bool virgil::sdk::crypto::Crypto::useSHA256Fingerprints ( ) const

Getter.

Returns
whether Crypto is using old algorithm to generate key fingerprints
Note
Current algorithm: first 8 bytes of SHA512 of public key in DER format. Old algorithm: SHA256 of public key in DER format. Use SHA256 fingerprint only if you need to work with encrypted data, that was encrypted using those fingerprint.
bool virgil::sdk::crypto::Crypto::verify ( const VirgilByteArray &  data,
const VirgilByteArray &  signature,
const keys::PublicKey signerPublicKey 
) const

Verifies digital signature of data.

Parameters
datadata that was signed
signaturedigital signature
signerPublicKeysigner public key
Returns
true if signature is verified, else otherwise
bool virgil::sdk::crypto::Crypto::verify ( std::istream &  istream,
const VirgilByteArray &  signature,
const keys::PublicKey signerPublicKey 
) const

Verifies digital signature of data stream.

Parameters
istreamdata stream that was signed
signaturedigital signature
signerPublicKeysigner public key
Returns
true if signature is verified, else otherwise

The documentation for this class was generated from the following file: