Library: Crypto
Package: Envelope
Header: Poco/Crypto/Envelope.h
Description
Envelope encrypts/decrypts data using a symmetric key.
Encryption and decryption with asymmetric keys is computationally expensive. To alleviate that, Envelope encrypts data using a symmetric session key; the key is then itself asymmetrically encrypted using a public key. It is also possible to encrypt the session key with multiple public keys, so that the message can be sent to multiple recipients.
Each recipient decrypts the session with their private key; the session key for the message decryption is the same for each recipient.
Member Summary
Member Functions: addKey, cipherNID, getContent, iv, keys, open, openAsString, seal, setContent, toString
Types Aliases
Byte
using Byte = unsigned char;
ByteVec
using ByteVec = std::vector < Byte >;
EVPPKeyVec
using EVPPKeyVec = std::vector < EVPPKey >;
EVP_PKEYVec
using EVP_PKEYVec = std::vector < EVP_PKEY * >;
EncKeyVec
using EncKeyVec = std::vector < ByteVec >;
Constructors
Envelope
Envelope() = delete;
Envelope
Envelope(
const EVPPKey & key,
int cipherNID
);
Creates a new Envelope object. Initialization vector is automatically generated.
Envelope
Envelope(
const EVPPKeyVec & keys,
int cipherNID
);
Creates a new Envelope object. Initialization vector is automatically generated.
Destructor
~Envelope
~Envelope();
Destroys the Envelope.
Member Functions
addKey
void addKey(
const EVPPKey & key
);
Adds the key to the list of private keys.
cipherNID
int cipherNID() const;
Reurns the cipher NID.
getContent
const ByteVec & getContent() const;
Returns the encrypted content.
iv
const ByteVec & iv() const;
Returns the initialization vector.
keys
const EncKeyVec & keys() const;
Returns encrypted symmetric keys.
open
ByteVec open(
const EVPPKey & privKey,
const ByteVec & encKeys,
const ByteVec & iv = ByteVec ()
);
Decrypts the stored encrypted data and returns it.
openAsString
std::string openAsString(
const EVPPKey & privKey,
const ByteVec & encKeys,
const ByteVec & iv = ByteVec ()
);
Decrypts the stored encrypted data and returns it.
seal
const ByteVec & seal(
const std::string & plainText
);
Encrypts the given text and returns the encrypted text.
seal
const ByteVec & seal(
const ByteVec & plainData
);
Encrypts the given data and returns the encrypted data.
setContent
void setContent(
const ByteVec & enc
);
Sets the encrypted content.
toString
static std::string toString(
const ByteVec & data
);
Converts and returns string from ByteVec.