Is my encryption safe as openPGP/SMIME?

后端 未结 4 901
滥情空心
滥情空心 2021-01-06 15:21

I\'m trying to write a simple file enc/decryption within a larger project. I\'d like to avoid libgpgme because of license issues. The openPGP standard is to complex for the

4条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-06 15:43

    Some observations:

    • The EVP_BytesToKey function is meant to create a key and initialization vector from a password and salt, not from random data. It will work, but you could also simply use the random bytes directly as key and initialization vector. (Make sure you are using a secure PRNG, I'm not sure what RAND_bytes actually does.)

    • The initialization vector does not need to be secret, CBC mode should be secure with a non-encrypted IV. (This does not hurt, though.)

    • The RSA encryption looks good (but you might want to use another padding, as David said).

    • As Serdalis said, you should also protect your file against modifications. Any keyed MAC will do (most common are HMAC build on a key and a hash function). Apply the MAC after encryption.

提交回复
热议问题