DemarcPoint
Member
- Joined
- Jan 20, 2016
- Messages
- 9
- Programming Experience
- Beginner
Greetings and thank you for the reply. However, I think your statement was a little presumptuous. I was in fact trying to understand who PBKDF2 works. For me, this is just a self learning project.
However, I was also trying to see if there was a way using Array.Copy to get the salt from the hash similar to the way "h**ps://dev.to/demg_dev/pbkdf2-hash-a-secure-password-5f8l" does it. What is done is these salt is included in the hash and it is retrieved from that same hash. This way, you don't have to store the hash and the salt because both would be included in the one hash.
Anyway, I do have a functional validation checker that I created but, it's not what I was looking to do. I was having a little difficulty figuring out how to get the Array.Copy to work coping the salt from the hash correctly with my code.
However, I was also trying to see if there was a way using Array.Copy to get the salt from the hash similar to the way "h**ps://dev.to/demg_dev/pbkdf2-hash-a-secure-password-5f8l" does it. What is done is these salt is included in the hash and it is retrieved from that same hash. This way, you don't have to store the hash and the salt because both would be included in the one hash.
Anyway, I do have a functional validation checker that I created but, it's not what I was looking to do. I was having a little difficulty figuring out how to get the Array.Copy to work coping the salt from the hash correctly with my code.
C#:
public bool IsValid(string testPassword, string origHash)
{
var TestPassword2 = Encoding.ASCII.GetBytes(testPassword);
var origSalt = Encoding.ASCII.GetBytes("7E2E837180B587ECC26795CFE0B7C4600B03F816"); // Test Salt
// Generate hash from test password and original test salt and iteration 2048.
// Compute the hash on the password the user entered.
IHash hash1 = HashHotel.Crypto.CreateSHA1();
IPBKDF2_HMAC pbkdf2 = HashHotel.KDF.PBKDF2_HMAC.CreatePBKDF2_HMAC(hash1, TestPassword2, origSalt, 2048);
byte[] Key = pbkdf2.GetBytes(24);
pbkdf2.Clear();
// Check Original hash against newly created hash using the test salt.
// Convert to Hex and if hash values match then return true.
var chString = Converters.ConvertBytesToHexString(Key, false);
if (chString == origHash)
{
return true;
}
else
{
// Nothing matches; return false.
return false;
}
}