Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub DemoHash()
- Dim d As New Encryption.Data( _
- "{ts '2004-10-09 08:10:04'}The world is beautiful and needs caring by its children")
- Dim hash As New Encryption.Hash(Encryption.Hash.Provider.SHA1)
- Dim hash2 As New Encryption.Hash(Encryption.Hash.Provider.SHA256)
- Dim hash3 As New Encryption.Hash(Encryption.Hash.Provider.SHA384)
- Dim hash4 As New Encryption.Hash(Encryption.Hash.Provider.SHA512)
- Dim hash5 As New Encryption.Hash(Encryption.Hash.Provider.MD5)
- Dim hash6 As New Encryption.Hash(Encryption.Hash.Provider.CRC32)
- hash.Calculate(d)
- hash2.Calculate(d)
- hash3.Calculate(d)
- hash4.Calculate(d)
- hash5.Calculate(d)
- Console.WriteLine("SHA1: " & hash.Value.Hex)
- Console.WriteLine("SHA256: " & hash2.Value.Hex)
- Console.WriteLine("SHA384: " & hash3.Value.Hex)
- Console.WriteLine("SHA512: " & hash4.Value.Hex)
- Console.WriteLine("MD5: " & hash5.Value.Hex)
- Console.WriteLine("CRC32: " & hash6.Calculate(d).Hex)
- Console.WriteLine()
- Dim salt As New Encryption.Data("salty!")
- Console.WriteLine("Salted CRC32: " & hash6.Calculate(d, salt).Hex)
- Console.WriteLine("Press ENTER to continue...")
- Console.ReadLine()
- End Sub
- Dim sUserName = "barry"
- Dim sPassWord = "fishlegs"
- Dim mySalt = "A deliciously salty string! fillED WIth all KindS of Junkk(&^&*(£"
- Dim d As New Encryption.Data(mySalt + sUserName + sPassWord)
- Dim hash As New Encryption.Hash(Encryption.Hash.Provider.SHA256)
- hash.Calculate(d)
- Dim sTheSaltedHashedUnPassCombination = hash.Value.Hex;
- SavenewPasswordHashToDatabase(sTheSaltedHashedUnPassCombination)
- Dim sUserName = "barry"
- Dim sPassWord = "fishlegs"
- Dim mySalt = "A deliciously salty string! fillED WIth all KindS of Junkk(&^&*(£"
- Dim d As New Encryption.Data(mySalt + sUserName + sPassWord)
- Dim hash As New Encryption.Hash(Encryption.Hash.Provider.SHA256)
- hash.Calculate(d)
- Dim sTheSaltedHashedUnPassCombination = hash.Value.Hex;
- SavenewPasswordHashToDatabase(sTheSaltedHashedUnPassCombination)
- Dim sThePreviouslyCreatedHashFromTheDatabase = GetHashForUserFromDatabase(usernameProvided)
- Dim mySalt = "A deliciously salty string! fillED WIth all KindS of Junkk(&^&*(£"
- Dim d As New Encryption.Data(mySalt + usernameProvided+ passwordProvided)
- Dim hash As New Encryption.Hash(Encryption.Hash.Provider.SHA256)
- hash.Calculate(d)
- Dim sTheSaltedHashedUnPassCombination = hash.Value.Hex;
- if (sThePreviouslyCreatedHashFromTheDatabase.Equals(sTheSaltedHashedUnPassCombination))
- 'UN & Password Valid!
- else
- 'UN & PW Invalid!
- end
- public static byte[] GetRandomSalt()
- {
- int minSaltSize = 16;
- int maxSaltSize = 32;
- Random random = new Random();
- int saltSize = random.Next(minSaltSize, maxSaltSize);
- saltBytes = new byte[saltSize];
- RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
- rng.GetNonZeroBytes(saltBytes);
- return saltBytes;
- }
- public static byte[] ComputeHash(string plainText)
- {
- byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText);
- HashAlgorithm hash = new SHA256Managed();
- return hash.ComputeHash(plainTextWithSaltBytes);
- }
- byte[] passwordHash = ComputeHash(password);
- byte[] salt = GetRandomSalt();
- byte[] saltHash = ComputeHash(salt);
- byte[] hashWithSaltBytes = new byte[hashBytes.Length + saltBytes.Length];
- for (int i=0; i < hashBytes.Length; i++)
- hashWithSaltBytes[i] = hashBytes[i];
- for (int i=0; i < saltBytes.Length; i++)
- hashWithSaltBytes[hashBytes.Length + i] = saltBytes[i];
- string hashValue = Convert.ToBase64String(hashWithSaltBytes);
Add Comment
Please, Sign In to add comment