OpenSSL AES_cfb128_encrypt C++

后端 未结 1 1636
一整个雨季
一整个雨季 2020-12-19 16:34

I tried to implement a \"very\" simple encryption/decryption example. I need it for a project where I would like to encrypt some user information. I can\'t encrypt the whole

相关标签:
1条回答
  • 2020-12-19 17:12

    The problem is that AES_cfb128_encrypt modifies the ivec (it has to in order to allow for chaining). Your solution is to create a copy of the ivec and initialize it before each call to AES_cfb128_encrypt as follows:

    const char ivecstr[AES_BLOCK_SIZE] = "goodbyworldkey\0";
    unsigned char ivec[AES_BLOCK_SIZE];
    memcpy( ivec , ivecstr, AES_BLOCK_SIZE);
    

    Then repeat the memcpy before your second call to AES_cfb128_encrypt.

    Note 1: Your initial vector was a byte too short, so I put an explicit additional \0 at the end of it. You should make sure all of your strings are of the correct length when copying or passing them.

    Note 2: Any code which uses encryption should REALLY avoid using strcpy or any other copy of unchecked length. It's a hazard.

    0 讨论(0)
提交回复
热议问题