Advertisement
ZeekoSec

MDSHA1

Apr 7th, 2015
541
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.65 KB | None | 0 0
  1.  
  2. Imports System.Security.Cryptography
  3. Imports System.Text
  4.  
  5. Namespace Hash
  6.     Public Class Hash
  7.         Public Sub New()
  8.         End Sub
  9.  
  10.         Public Enum HashType As Integer
  11.             MD5
  12.             SHA1
  13.             SHA256
  14.             SHA512
  15.         End Enum
  16.  
  17.         Public Shared Function GetHash(text As String, hashType__1 As HashType) As String
  18.             Dim hashString As String
  19.             Select Case hashType__1
  20.                 Case HashType.MD5
  21.                     hashString = GetMD5(text)
  22.                     Exit Select
  23.                 Case HashType.SHA1
  24.                     hashString = GetSHA1(text)
  25.                     Exit Select
  26.                 Case HashType.SHA256
  27.                     hashString = GetSHA256(text)
  28.                     Exit Select
  29.                 Case HashType.SHA512
  30.                     hashString = GetSHA512(text)
  31.                     Exit Select
  32.                 Case Else
  33.                     hashString = "Invalid Hash Type"
  34.                     Exit Select
  35.             End Select
  36.             Return hashString
  37.         End Function
  38.  
  39.         Public Shared Function CheckHash(original As String, hashString As String, hashType As HashType) As Boolean
  40.             Dim originalHash As String = GetHash(original, hashType)
  41.             Return (originalHash = hashString)
  42.         End Function
  43.  
  44.         Private Shared Function GetMD5(text As String) As String
  45.             Dim UE As New UnicodeEncoding()
  46.             Dim hashValue As Byte()
  47.             Dim message As Byte() = UE.GetBytes(text)
  48.  
  49.             Dim hashString As MD5 = New MD5CryptoServiceProvider()
  50.             Dim hex As String = ""
  51.  
  52.             hashValue = hashString.ComputeHash(message)
  53.             For Each x As Byte In hashValue
  54.                 hex += [String].Format("{0:x2}", x)
  55.             Next
  56.             Return hex
  57.         End Function
  58.  
  59.         Private Shared Function GetSHA1(text As String) As String
  60.             Dim UE As New UnicodeEncoding()
  61.             Dim hashValue As Byte()
  62.             Dim message As Byte() = UE.GetBytes(text)
  63.  
  64.             Dim hashString As New SHA1Managed()
  65.             Dim hex As String = ""
  66.  
  67.             hashValue = hashString.ComputeHash(message)
  68.             For Each x As Byte In hashValue
  69.                 hex += [String].Format("{0:x2}", x)
  70.             Next
  71.             Return hex
  72.         End Function
  73.  
  74.         Private Shared Function GetSHA256(text As String) As String
  75.             Dim UE As New UnicodeEncoding()
  76.             Dim hashValue As Byte()
  77.             Dim message As Byte() = UE.GetBytes(text)
  78.  
  79.             Dim hashString As New SHA256Managed()
  80.             Dim hex As String = ""
  81.  
  82.             hashValue = hashString.ComputeHash(message)
  83.             For Each x As Byte In hashValue
  84.                 hex += [String].Format("{0:x2}", x)
  85.             Next
  86.             Return hex
  87.         End Function
  88.  
  89.         Private Shared Function GetSHA512(text As String) As String
  90.             Dim UE As New UnicodeEncoding()
  91.             Dim hashValue As Byte()
  92.             Dim message As Byte() = UE.GetBytes(text)
  93.  
  94.             Dim hashString As New SHA512Managed()
  95.             Dim hex As String = ""
  96.  
  97.             hashValue = hashString.ComputeHash(message)
  98.             For Each x As Byte In hashValue
  99.                 hex += [String].Format("{0:x2}", x)
  100.             Next
  101.             Return hex
  102.         End Function
  103.     End Class
  104. End Namespace
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement