【发布时间】:2017-11-03 10:13:01
【问题描述】:
我正在尝试使用 php 和 c 创建一个 openssl aes 加密/解密。我能够使用 php 和 openssl 加密文本,这将在 base64 字符串中输出加密字符串。我正在尝试将此base64编码的字符串传递给c程序以使用c中的openssl对其进行解码。
int decrypt(unsigned char *ciphertext,
int ciphertext_len,
unsigned char *key,
unsigned char *iv,
unsigned char *plaintext)
{
EVP_CIPHER_CTX *ctx;
int len;
int plaintext_len;
/* Create and initialise the context */
if(!(ctx = EVP_CIPHER_CTX_new())) handleErrors();
if(1 != EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, key, iv))
handleErrors();
if(1 != EVP_DecryptUpdate(ctx, plaintext, &len, ciphertext, ciphertext_len))
handleErrors();
plaintext_len = len;
if(1 != EVP_DecryptFinal_ex(ctx, plaintext + len, &len)) handleErrors();
plaintext_len += len;
/* Clean up */
EVP_CIPHER_CTX_free(ctx);
return plaintext_len;
}
有什么方法可以在 c 中使用 openssl 解密 base64 字符串吗?我可以使用类似于
的命令行来解密它openssl enc -aes-256-cbc -d -in file.encrypted -nosalt -nopad -K 31323334353637383132333435363738 -iv 31323334353637383132333435363738
提前致谢
【问题讨论】:
-
klutt,谢谢你的回复,解码后我也想用openssl解密
-
这里是一个使用cbc的例子(不推荐使用)wiki.openssl.org/index.php/…