This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] CC3235MODASF:AES_ECB 加密问题

Guru**** 2478765 points


请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/wireless-connectivity/wi-fi-group/wifi/f/wi-fi-forum/1427024/cc3235modasf-issues-with-aes_ecb-encryption

器件型号:CC3235MODASF

工具与软件:

您好!

我使用 AES_CCB 加密对 字符串进行加密。 我解密它以检查是否正确完成。 加密/解密 每5秒发生一次。 我发现有时无法完全解密数据,尽管 CryptoCC32XX_encrypt ()和 CryptoCC32XX_Decrypt()   的返回值都是 CryptoCC32XX_STATUS_SUCCESS。 我尝试查看参数 outLen (即加密数据的大小)是否有任何帮助、但只要加密/解密成功、该参数始终为0。

我的代码片段:

CryptoCC32XX_Handle cryptoHandle1;

CryptoCC32XX_EncryptParams aesCCMParams, decryptParams;

CryptoCC32XX_EncryptMethod method = CryptoCC32XX_AES_ECB;

void init()
{
    cryptoHandle1 = CryptoCC32XX_open(0, CryptoCC32XX_AES);
}




void EncryptData(char *inputBuf, char *outputBuf, char *encryptionKey)

{

int32_t retVal = -1;
char checkBuf[512] = { '\0' };
aesParams.aes.pKey = (const uint8_t*) (encryptionKey);
decryptParams = aesParams;
size_t padded_len = 0;
size_t encryptedDataLength = 0;
size_t decryptedDataLength = 0;

pkcs5_pad(inputBuf, strlen(inputBuf), &padded_len);

retVal = CryptoCC32XX_encrypt(cryptoHandle1, method, inputBuf,
strlen(inputBuf), outputBuf,
&encryptedDataLength, &aesCCMParams);

UART_PRINT("\n encrypted data length %d\n",encryptedDataLength);

if (retVal == 0)
{

retVal = CryptoCC32XX_decrypt(cryptoHandle1, method, outputBuf,
strlen(outputBuf), &checkBuf[0],
&decryptedDataLength, &decryptParams);

UART_PRINT("decrypted data %s \n", &checkBuf);

}

您能不能指导我解决什么问题?

谢谢!

SN

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 SN:

    如何创建 checkBuf? 另外、在解密函数中、请尝试按照传入 outputBuf 的方式仅传递缓冲区名称。

    此致!

    Rogelio

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Rogelio:

    1. checkBuf 是 EncryptData 函数的本地阵列、它同时进行加密和解密

    2.缓冲区名称是这样传递的,因为 API 需要一个指针。 传递&checkBuf 和 checkBuf 之间没有区别。