AES encryption of 16 bytes without padding

后端 未结 2 617
忘掉有多难
忘掉有多难 2021-01-20 04:21

This should be a simple question, but I can\'t find any examples or figure out the answer from the openssl docs.

I want to encrypt exactly 128 bits,

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-20 04:39

    Here, you have already figured out the steps. So, it will be

    1. EVP_encryptInit_ex
    2. EVP_EncryptUpdate_ex
    3. EVP_EncryptFinal_ex

    EVP_EncryptFinal_ex also take care of the fact that data is not in multiple of block lengths.

    In my opinion, if you have only to use AES with no padding (EVP_ interfaces takes care of padding), then go for AES_encrypt.

    They are fairly easy to use.

    //Step 1: Set encrypt key.
    AES_KEY aeskey;
    AES_set_encrypt_key(key, bits, &aeskey);
    //Step2: Encrypt exactly 128 bits.
    AES_encrypt(data, dataout, &aeskey);
    

提交回复
热议问题