michael I like your code, looks good. I got a class code that will hash in MD5, S
HA1, SHA256, SHA384, SHA512. As far as salt I use DateTime.Now anyway I would like to post the Class that I use here, it may help someone.
Imports Microsoft.VisualBasic
Imports System.Security.Cryptography
Imports System.Text
Public Class Hashing
'Algorithm Enermations
Public Enum HashAlgorithmTypes
MD5
SHA1
SHA256
SHA384
SHA512
End Enum
'******************************************************************************
Public Shared Function CreateHash(ByVal valueToHash As String, _
ByVal algorithmType As HashAlgorithmTypes) As String
'Set up variables
Dim algorithm As System.Security.Cryptography.HashAlgorithm
Dim encoder As ASCIIEncoding = New ASCIIEncoding()
Dim valueByteArray As Byte() = encoder.GetBytes(valueToHash)
Dim hashValue As String = ""
Dim hashValueByteArray As Byte()
'Acquire algorithm object
Select Case algorithmType
Case HashAlgorithmTypes.SHA1
algorithm = New SHA1Managed()
Case HashAlgorithmTypes.SHA256
algorithm = New SHA256Managed()
Case HashAlgorithmTypes.SHA384
algorithm = New SHA384Managed()
Case HashAlgorithmTypes.SHA512
algorithm = New SHA512Managed()
Case Else 'use MD5
algorithm = New MD5CryptoServiceProvider
End Select
'Create binary hash
hashValueByteArray = algorithm.ComputeHash(valueByteArray)
'Convert binary hash to hex
For Each b As Byte In hashValueByteArray
hashValue &= String.Format("{0:x2}", b)
Next
Return hashValue
End Function
End Class
|
Then to call the Class from a page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myhash As String
myhash = TextBox1.Text
MD5.Text = Hashing.CreateHash(myhash, Hashing.HashAlgorithmTypes.MD5)
SHA1.Text = Hashing.CreateHash(myhash, Hashing.HashAlgorithmTypes.SHA1)
SHA256.Text = Hashing.CreateHash(myhash, Hashing.HashAlgorithmTypes.SHA256)
SHA384.Text = Hashing.CreateHash(myhash, Hashing.HashAlgorithmTypes.SHA384)
SHA512.Text = Hashing.CreateHash(myhash, Hashing.HashAlgorithmTypes.SHA512)
End Sub
|
This way you can pick what you want.