使用openssl解密AES-GCM文件

使用openssl解密AES-GCM文件,openssl,aes,encryption,aes-gcm,Openssl,Aes,Encryption,Aes Gcm,我目前正在尝试使用openssl解密给定的文本。我尝试使用下面给出的示例编写自己的代码: 但我最后还是有一个坏结果。我的解密函数如下: 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) { i

我目前正在尝试使用openssl解密给定的文本。我尝试使用下面给出的示例编写自己的代码: 但我最后还是有一个坏结果。我的解密函数如下:

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);
}
除AAD之外的所有数据都是通过读取文本文件给出的(我有一个加密数据列表、使用的密钥/Ivs、MAC和解密后的预期结果) 经过几次试验后,出现了以下问题: -结果与预期的不同 -修改MAC不会影响结果(明文) -抑制AAD不会影响结果

我真的不知道为什么它不起作用。 如果你有任何想法,提示或具体的例子,这将是一个很大的帮助


致以最诚挚的问候

问题解决了。程序提供的AAD是错误的