简体   繁体   English

使用openssl解密AES-GCM文件

[英]Decryption of AES-GCM files using openssl

I'm currently trying to decrypt a given text using openssl. 我目前正在尝试使用openssl解密给定的文本。 I tried to make my own code using the example given there : Late authentication in OpenSSL GCM decryption but i still have a bad result in the end. 我尝试使用那里给出的示例制作我自己的代码: OpenSSL GCM解密中的后期身份验证,但最终我仍然有一个糟糕的结果。 My decryption function is as followed : 我的解密功能如下:

void aes_decrypt(EVP_CIPHER_CTX ctx, unsigned char *pCipherText,
    int pCipherTextLen, int AADLen, unsigned char* pKey, unsigned char* pIv,
    unsigned char* pMac, int MacLen) {
int bytesProcessed = 12;
int dec_success;

}
unsigned char * pOut = malloc(pCipherTextLen);
unsigned char * pAAD = malloc(AADLen);
unsigned char * pClearText = malloc(pCipherTextLen);

// setting cipher, key and iv
EVP_DecryptInit(&ctx, EVP_aes_256_gcm(), pKey, pIv);
// setting tag
EVP_CIPHER_CTX_ctrl(&ctx, EVP_CTRL_GCM_SET_IVLEN, 24, NULL);
EVP_CIPHER_CTX_ctrl(&ctx, EVP_CTRL_GCM_SET_TAG, 16, pMac);
// adding Additional Authenticated Data (AAD)
EVP_DecryptUpdate(&ctx, NULL, &bytesProcessed, pAAD, AADLen);
// decrypting data
EVP_DecryptUpdate(&ctx, pClearText, &bytesProcessed, pCipherText,
        pCipherTextLen);
// authentication step
dec_success = EVP_DecryptFinal(&ctx, pOut, &bytesProcessed);
free(pOut);
free(pMac);
free(pAAD);
free(pClearText);
}

All the data but the AAD are given previously by reading textfiles (I have a list of encrypted data, the key/Ivs used, the MAC and the result expected after decryption) After a few experiments, the following issues occures: - the result is diferent than the one expected - modifying the MAC doesn't affect the result (cleartext) - suppressing the AAD doesn't affect the results. 之前通过读取文本文件给出了除AAD之外的所有数据(我有加密数据列表,使用的密钥/ Iv,MAC和解密后预期的结果)经过几次实验后,出现以下问题: - 结果是与预期的不同 - 修改MAC不会影响结果(明文) - 抑制AAD不会影响结果。

I realy doesn't know why it doesn't work. 我真的不知道为什么它不起作用。 If you have any idea, tips or concret example, it would be a big help 如果你有任何想法,提示或具体的例子,那将是一个很大的帮助

Best regards 最好的祝福

The problem is solved. 问题已经解决了。 The AAD provided by the program was wrong 该计划提供的AAD是错误的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM