标签归档: decrypt

OPENSSL AES解密文件遇到的一个小坑

    openssl aes解密需要用到 EVP_CIPHER_CTX_new EVP_DecryptInit_ex EVP_DecryptUpdate EVP_DecryptFinal_ex EVP_CIPHER_CTX_free 五个函数。

默认启用了填充,如果不需要需调用EVP_CIPHER_CTX_set_padding设成0禁用。

在解密大文件的时候需要持续调用EVP_DecryptUpdate来解密,我犯了个错误就是inbuf大小和outbuf大小设成一样,出问题查官方文档才知道outbuf大小要比inbuf大。

EVP_DecryptInit_ex(), EVP_DecryptUpdate() and EVP_DecryptFinal_ex() are the corresponding decryption operations. EVP_DecryptFinal() will return an error code if padding is enabled and the final block is not correctly formatted. The parameters and restrictions are identical to the encryption operations except that if padding is enabled the decrypted data buffer out passed to EVP_DecryptUpdate() should have sufficient room for (inl + cipher_block_size) bytes unless the cipher block size is 1 in which case inl bytes is sufficient.

网上的代码不能乱抄啊!看官方文档的重要性。

https://www.openssl.org/docs/man1.0.2/crypto/EVP_DecryptUpdate.html

https://wiki.openssl.org/index.php/EVP_Symmetric_Encryption_and_Decryption