private void MakeFail(string strData, string testValue, int saltLength) { string strHash, strSalt; SaltedHash sh = new SaltedHash(new SHA256Managed(), saltLength); sh.GetHashAndSalt(strData, out strHash, out strSalt); Assert.IsFalse(sh.VerifyHash(testValue, strHash, strSalt), "Should not verify"); }
private void HashAndVerify(int saltLength, int dataLength) { byte[] binData = new byte[dataLength]; byte[] binHash, binSalt; string strData = string.Empty; string strHash, strSalt; for (int index = 0; index < dataLength; index++) { binData[index] = (byte)index; strData += index.ToString().Last(); } SaltedHash sh = new SaltedHash(new SHA256Managed(), saltLength); sh.GetHashAndSalt(binData, out binHash, out binSalt); Assert.IsTrue(sh.VerifyHash(binData, binHash, binSalt), "Verfiy failed"); sh.GetHashAndSalt(strData, out strHash, out strSalt); Assert.IsTrue(sh.VerifyHash(strData, strHash, strSalt), "Verfiy failed"); }
private void CheckSaltLength(int saltLength, int dataLength) { byte[] binData = new byte[dataLength]; byte[] binHash, binSalt; string strData = string.Empty; string strHash, strSalt; for (int index = 0; index < dataLength; index++) { binData[index] = (byte)index; strData += index.ToString().Last(); } SaltedHash sh = new SaltedHash(new SHA256Managed(), saltLength); sh.GetHashAndSalt(binData, out binHash, out binSalt); Assert.AreEqual(saltLength, binSalt.Length, "Binary salt is wrong length"); sh.GetHashAndSalt(strData, out strHash, out strSalt); byte[] strSaltAsBin = Convert.FromBase64String(strSalt); Assert.AreEqual(saltLength, strSaltAsBin.Length, "String salt is wrong length"); }