Advertisement
TheVideoVolcano

Encryption Algorithms - VB.NET

Jan 3rd, 2014
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.10 KB | None | 0 0
  1. 'SHA-512
  2.  
  3.  Public Function EncryptSHA512Managed(ByVal rawstring As String) As String
  4.         Dim sha512 As System.Security.Cryptography.SHA512 = New System.Security.Cryptography.SHA512Managed()
  5.         Dim sha512Bytes As Byte() = System.Text.Encoding.Default.GetBytes(rawstring)
  6.         Dim cryString As Byte() = sha512.ComputeHash(sha512Bytes)
  7.         Dim sha512Str As String = String.Empty
  8.         For i As Integer = 0 To cryString.Length - 1
  9.             sha512Str += cryString(i).ToString("X")
  10.         Next
  11.         Return sha512Str
  12.     End Function
  13.  
  14. 'MD5
  15.  
  16. Public Function Md5FromString(ByVal rawString As String) As String
  17.  
  18.         Dim Bytes() As Byte
  19.         Dim sb As New StringBuilder()
  20.  
  21.         If String.IsNullOrEmpty(rawString) Then
  22.             Throw New ArgumentNullException
  23.         End If
  24.         Bytes = Encoding.Default.GetBytes(rawString)
  25.         Bytes = MD5.Create().ComputeHash(Bytes)
  26.  
  27.         For x As Integer = 0 To Bytes.Length - 1
  28.             sb.Append(Bytes(x).ToString("x2"))
  29.         Next
  30.  
  31.         Return sb.ToString()
  32.  
  33.     End Function
  34.  
  35. 'WILL ADD MORE IN THE FUTURE!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement