37 #ifndef _PROTOBUF_COMM_CRYPTO_H_
38 #define _PROTOBUF_COMM_CRYPTO_H_
44 # include <openssl/ossl_typ.h>
47 namespace protobuf_comm {
52 BufferEncryptor(
const std::string &key, std::string cipher_name =
"AES-128-ECB");
55 void encrypt(
const std::string &plain, std::string &enc);
69 long long unsigned int iv_;
72 const EVP_CIPHER *cipher_;
84 size_t decrypt(
int cipher,
const void *enc,
size_t enc_size,
void *plain,
size_t plain_size);
87 void generate_key(
int cipher);
91 std::map<int, std::string> keys_;
95 const char *cipher_name_by_id(
int cipher);
96 int cipher_name_to_id(
const char *cipher);
98 const EVP_CIPHER *cipher_by_id(
int cipher);
99 const EVP_CIPHER *cipher_by_name(
const char *cipher);
Decrypt buffers encrypted with BufferEncryptor.
BufferDecryptor(const std::string &key)
Constructor.
~BufferDecryptor()
Destructor.
size_t decrypt(int cipher, const void *enc, size_t enc_size, void *plain, size_t plain_size)
Decrypt a buffer.
Encrypt buffers using AES128 in ECB mode.
BufferEncryptor(const std::string &key, std::string cipher_name="AES-128-ECB")
Constructor.
size_t encrypted_buffer_size(size_t plain_length)
Get required size for an encrypted buffer of the given plain text length.
~BufferEncryptor()
Destructor.
void encrypt(const std::string &plain, std::string &enc)
Encrypt a buffer.
int cipher_id() const
Get cipher ID.