hey, I'd like to store the hash of a password on the phone, but I'm not sure how to do it. I can only seem to find encryption methods. What's the best way to hash the password? thanks
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
UPDATE: THIS ANSWER IS SERIOUSLY OUTDATED. Please use the recommendations from the https://stackoverflow.com/a/10402129/251311 instead.
You can either use
or
To get
data
as byte array you could useand to get back string from
md5data
orsha1data
Most of the other answers here are somewhat out-of-date with today's best practices. As such here is the application of using PBKDF2/Rfc2898DeriveBytes to store and verify passwords. The following code is in a stand-alone class in this post: Another example of how to store a salted password hash. The basics are really easy, so here it is broken down:
STEP 1 Create the salt value with a cryptographic PRNG:
STEP 2 Create the Rfc2898DeriveBytes and get the hash value:
STEP 3 Combine the salt and password bytes for later use:
STEP 4 Turn the combined salt+hash into a string for storage
STEP 5 Verify the user-entered password against a stored password
Note: Depending on the performance requirements of your specific application, the value '10000' can be reduced. A minimum value should be around 1000.
Based on csharptest.net's great answer, I have written a Class for this:
Usage:
A sample hash could be this:
As you can see, I also have included the iterations in the hash for easy usage and the possibility to upgrade this, if we need to upgrade.
I use a hash and a salt for my password encryption (it's the same hash that Asp.Net Membership uses):