Ser*_*gey 5 c encryption aes mbed
我使用 mbedtls 库编写了以下简单的加密解密程序。加密工作正常(根据http://aes.online-domain-tools.com/检查)。但是,当解密回来时,我得到不正确的结果(输出2和输入不同)。我是否滥用了该库?
int main()
{
mbedtls_aes_context aes;
mbedtls_aes_context aes2;
unsigned char key[16] = "itzkbgulrcsjmnv";
key[15] = 'x';
unsigned char iv[16] = {0xb2, 0x4b, 0xf2, 0xf7, 0x7a, 0xc5, 0xec, 0x0c, 0x5e, 0x1f, 0x4d, 0xc1, 0xae, 0x46, 0x5e, 0x75};
const unsigned char *input = (const unsigned char*) "Some string to b";
unsigned char output[128] = {0};
unsigned char output2[128] = {0};
mbedtls_aes_setkey_enc( &aes, key, 16*8 );
mbedtls_aes_crypt_cbc( &aes, MBEDTLS_AES_ENCRYPT, strlen((const char*)input), iv, input, output );
mbedtls_aes_setkey_dec( &aes2, key, 16*8 );
mbedtls_aes_crypt_cbc( &aes2, MBEDTLS_AES_DECRYPT, strlen((const char*)output), iv, output, output2 );
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4896 次 |
| 最近记录: |