代码
#include <cstring>
#include <memory>
#include <openssl/aes.h>
#include <openssl/md5.h>
namespace hsm{
namespace mgmt{
void get_md5_digest(const std::string &data,uint8_t result[16]){
MD5_CTX md5_ctx{};
MD5_Init(&md5_ctx);
MD5_Update(&md5_ctx,data.c_str(),data.length());
MD5_Final(result,&md5_ctx);
}
/**
* @brief generate a valid aes key from input password
*
* @note AES only support keys with length 128/192/256bits
* @note this implementation use md5 as a method to fix the password
*/
std::unique_ptr<AES_KEY> get_aes_key(const std::string &password,int flag){
auto aes_key = std::make_unique<AES_KEY>();
uint8_t data[16]{};
get_md5_digest(password,data);
if (flag == AES_ENCRYPT){
AES_set_encrypt_key(data,siz