37 #ifndef __PROTOBUF_COMM_CRYPTO_H_ 38 #define __PROTOBUF_COMM_CRYPTO_H_ 44 # include <openssl/ossl_typ.h> 54 BufferEncryptor(
const std::string &key, std::string cipher_name =
"AES-128-ECB");
57 void encrypt(
const std::string &plain, std::string &enc);
62 {
return cipher_id_; }
68 long long unsigned int iv_;
70 const EVP_CIPHER *cipher_;
81 size_t decrypt(
int cipher,
const void *enc,
size_t enc_size,
void *plain,
size_t plain_size);
84 void generate_key(
int cipher);
88 std::map<int, std::string> keys_;
91 const char * cipher_name_by_id(
int cipher);
92 int cipher_name_to_id(
const char *cipher);
95 const EVP_CIPHER * cipher_by_id(
int cipher);
96 const EVP_CIPHER * cipher_by_name(
const char *cipher);
BufferEncryptor(const std::string &key, std::string cipher_name="AES-128-ECB")
Constructor.
~BufferEncryptor()
Destructor.
Decrypt buffers encrypted with BufferEncryptor.
size_t encrypted_buffer_size(size_t plain_length)
Get required size for an encrypted buffer of the given plain text length.
int cipher_id() const
Get cipher ID.
Encrypt buffers using AES128 in ECB mode.
void encrypt(const std::string &plain, std::string &enc)
Encrypt a buffer.