开发者

How to handle salt in password based encryption

开发者 https://www.devze.com 2023-04-11 10:12 出处:网络
I\'m learning to do proper crytographic implementations, and I thought as an exercise I would create an encrypted text editor.

I'm learning to do proper crytographic implementations, and I thought as an exercise I would create an encrypted text editor.

My first attempt used a SHA-512 hash of a user-provided password as the key, and it functioned just fine.开发者_运维知识库 Though I was storing the IV in the header of the file, unprotected and that had me worried.

Then I read on stackoverflow that I should be using SecretKeyFactory (I'm using Java) to do PBE, and now I additionally need to provide a salt. So now I'm storing the salt in the header as well, but that would seem to ruin the whole purpose of having a salt. So how is this supposed to work? When I have Alice pick a password for her file when she saves, am I supposed to say "Here, memorize this random number along with your password."? I would like for the resulting file to be able to be e-mailed to Bob, so the salt can't be stored locally.

As my app stands, the IV and salt are out in the open. I would like for my user to only have to know the password when they send their file to Bob while remaining cryptographically secure, but I can't find any examples of how this is done.

Thanks for any help!


It is safe to store an IV along with the data, that is how IVs are used. Your method is ok, pick a block cipher, use cipher block chaining and an IV, and you're away.


There are many ways to create a key and iv from a passphrase, but one of the more common ones involves HMAC with SHA-1, in an algorithm that takes some salt and other things into account, to build a sufficiently bit-mixed key and iv.

The technical standard is the PKCS#5 v2.0 PBKDF2 algorithm, to which OpenSSL implements a C interface to a method that can do this, but as far as I know, no command line method.

0

精彩评论

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

关注公众号