开发者

How to store salt and IV in file cocoa?

开发者 https://www.devze.com 2023-04-11 01:06 出处:网络
So I have implemented salts and IVs, but the decryption is now a bit buggy. Of course, I need both the salt and IV for decryption as well, but the user can\'t enter that... I need to be able to store

So I have implemented salts and IVs, but the decryption is now a bit buggy. Of course, I need both the salt and IV for decryption as well, but the user can't enter that... I need to be able to store both the salt and IV in the encrypted file, then retrieve the salt and IV when the user is decrypting the file. How would I go about doing this? How would I go ab开发者_如何学运维out storing and retrieving that data?


As Peter said, the initialization vector and the salt for key derivation should be stored together with the encrypted file, in a header or such.

Instead of creating your own ad-hoc file format for encrypted storage, have a look at the OpenPGP message format (as used by both PGP and GnuPG, and maybe other programs). It is specified in RFC 4880. You will likely not have to implement all of it, but grab the portions that you need for your application.

As an added bonus, the user can then use PGP/GPG (with the right options and the password/key) to decrypt the data, if your program should somehow cease to work.


Store them along with the ciphertext. You'll need to come up with a suitable file format in which to do it; a keyed archiver will make it easy.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号