Ermittelt den Hashwert aus einem angegebenen String. Um z. B. Passwörter sicher (in der Datenbank) abzulegen
''' -----------------------------------------------------------------------------
''' <summary>
''' Ermittelt den Hashwert eines übergebenen Strings
''' </summary>
''' <param name="Value">String dessen Hashwert ermittelt werden soll</param>
''' <returns>den HashWert de sübergebenen Strings.
''' Einen String wie z. B:
''' "D4-1D-8C-D9-8F-00-B2-04-E9-80-09-98-EC-F8-42-7E"</returns>
''' -----------------------------------------------------------------------------
Public Shared Function ConvertToHash(ByVal Value As String) As String
Dim data1ToHash As Byte() = ConvertStringToByteArray(Value)
Dim hashvalue As Byte() = CType(System.Security.Cryptography.CryptoConfig.CreateFromName("MD5"), System.Security.Cryptography.HashAlgorithm).ComputeHash(data1ToHash)
Return System.BitConverter.ToString(hashvalue)
End Function 'ConvertToHash
Public Shared Function ConvertStringToByteArray(ByVal s As String) As Byte()
Return (New System.Text.UnicodeEncoding).GetBytes(s)
End Function 'ConvertStringToByteArray
1 Kommentare zum Snippet