OpenSSL EVP_CIPHER_CTX_set_padding无效

时间:2017-01-04 22:55:38

标签: openssl aes padding

我正在尝试使用EVP接口使用AES,CBC和PKCS#7填充进行加密/解密。我使用的是example found on the Wiki

我在创建并初始化不应添加填充的上下文后执行EVP_CIPHER_CTX_set_padding(ctx, 0),如果明文不是16字节的倍数则失败。尽管如此,密文总是包含一个仅由填充组成的额外块。

我正在使用的代码从教程中逐字复制和粘贴,我只在加密和解密中添加EVP_CIPHER_CTX_set_padding(ctx, 0),如下所示:

/* Create and initialise the context */
if (!(ctx = EVP_CIPHER_CTX_new())) handleErrors();
EVP_CIPHER_CTX_set_padding(ctx, 0);

我做错了吗?

1 个答案:

答案 0 :(得分:5)

显然,Sub GoToRoomSchedule() ' ' GoToRoomSchedule Macro ' Set up Workbook as a reference to Cell J9 contents (MonthYear based on calendar selection) ' Set up Worksheet as a reference to Cell H4 contents (Day of month based on calendar selection) Dim WBook As String Dim FileName As String FileName = Range("J4") WBook = FileName Workbooks(FileName).Activate Dim WSheet As String Dim SheetName As String SheetName = Range("H4") WSheet = SheetName Sheets(SheetName).Select End Sub EVP_DecryptInit_ex都会重新初始化上下文,因此在调用这些方法之后应该执行任何上下文更改(例如设置填充)。