Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Security.Cryptography
- Imports System.Text
- Namespace Hash
- Public Class Hash
- Public Sub New()
- End Sub
- Public Enum HashType As Integer
- MD5
- SHA1
- SHA256
- SHA512
- End Enum
- Public Shared Function GetHash(text As String, hashType__1 As HashType) As String
- Dim hashString As String
- Select Case hashType__1
- Case HashType.MD5
- hashString = GetMD5(text)
- Exit Select
- Case HashType.SHA1
- hashString = GetSHA1(text)
- Exit Select
- Case HashType.SHA256
- hashString = GetSHA256(text)
- Exit Select
- Case HashType.SHA512
- hashString = GetSHA512(text)
- Exit Select
- Case Else
- hashString = "Invalid Hash Type"
- Exit Select
- End Select
- Return hashString
- End Function
- Public Shared Function CheckHash(original As String, hashString As String, hashType As HashType) As Boolean
- Dim originalHash As String = GetHash(original, hashType)
- Return (originalHash = hashString)
- End Function
- Private Shared Function GetMD5(text As String) As String
- Dim UE As New UnicodeEncoding()
- Dim hashValue As Byte()
- Dim message As Byte() = UE.GetBytes(text)
- Dim hashString As MD5 = New MD5CryptoServiceProvider()
- Dim hex As String = ""
- hashValue = hashString.ComputeHash(message)
- For Each x As Byte In hashValue
- hex += [String].Format("{0:x2}", x)
- Next
- Return hex
- End Function
- Private Shared Function GetSHA1(text As String) As String
- Dim UE As New UnicodeEncoding()
- Dim hashValue As Byte()
- Dim message As Byte() = UE.GetBytes(text)
- Dim hashString As New SHA1Managed()
- Dim hex As String = ""
- hashValue = hashString.ComputeHash(message)
- For Each x As Byte In hashValue
- hex += [String].Format("{0:x2}", x)
- Next
- Return hex
- End Function
- Private Shared Function GetSHA256(text As String) As String
- Dim UE As New UnicodeEncoding()
- Dim hashValue As Byte()
- Dim message As Byte() = UE.GetBytes(text)
- Dim hashString As New SHA256Managed()
- Dim hex As String = ""
- hashValue = hashString.ComputeHash(message)
- For Each x As Byte In hashValue
- hex += [String].Format("{0:x2}", x)
- Next
- Return hex
- End Function
- Private Shared Function GetSHA512(text As String) As String
- Dim UE As New UnicodeEncoding()
- Dim hashValue As Byte()
- Dim message As Byte() = UE.GetBytes(text)
- Dim hashString As New SHA512Managed()
- Dim hex As String = ""
- hashValue = hashString.ComputeHash(message)
- For Each x As Byte In hashValue
- hex += [String].Format("{0:x2}", x)
- Next
- Return hex
- End Function
- End Class
- End Namespace
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement