Imports System.Text
Imports System.Security.Cryptography
Imports System.IO

Public Class MyFunction
    Public Function Encrypt(ByVal strText As String) As String
        Dim strEncrKey As String = "c8YXEft&+fMs@]ntv2!JyUuFs[#xgXek"
        Dim byKey() As Byte = {}
        Dim IV() As Byte = {&H33, &H62, &H57, &H33, &H23, &H40, &H6A, &H75, &H72, &H5B, &H5F, &H42, &H50, &H55, &H76, &H73}
        Try
            byKey = System.Text.Encoding.UTF8.GetBytes(strEncrKey.Substring(0, 16))

            Dim rijndael As New RijndaelManaged()
            Dim inputByteArray() As Byte = Encoding.UTF8.GetBytes(strText)
            Dim ms As New MemoryStream()
            Dim cs As New CryptoStream(ms, rijndael.CreateEncryptor(byKey, IV), CryptoStreamMode.Write)
            cs.Write(inputByteArray, 0, inputByteArray.Length)
            cs.FlushFinalBlock()
            Return Convert.ToBase64String(ms.ToArray())

        Catch ex As Exception
            Return ex.Message
        End Try

    End Function
    Public Function Decrypt(ByVal strText As String) As String
        Dim sDecrKey As String = "c8YXEft&+fMs@]ntv2!JyUuFs[#xgXek"
        Dim byKey() As Byte = {}
        Dim IV() As Byte = {&H33, &H62, &H57, &H33, &H23, &H40, &H6A, &H75, &H72, &H5B, &H5F, &H42, &H50, &H55, &H76, &H73}
        Dim inputByteArray(strText.Length) As Byte

        Try
            byKey = System.Text.Encoding.UTF8.GetBytes(sDecrKey.Substring(0, 16))
            Dim rijn As New RijndaelManaged()
            inputByteArray = Convert.FromBase64String(strText)
            Dim ms As New MemoryStream()
            Dim cs As New CryptoStream(ms, rijn.CreateDecryptor(byKey, IV), CryptoStreamMode.Write)

            cs.Write(inputByteArray, 0, inputByteArray.Length)
            cs.FlushFinalBlock()
            Dim encoding As System.Text.Encoding = System.Text.Encoding.UTF8

            Return encoding.GetString(ms.ToArray())

        Catch ex As Exception
            Return ex.Message
        End Try
    End Function
    Public Function MD5StringHash(ByVal strString As String) As String
        Dim MD5 As New MD5CryptoServiceProvider
        Dim Data As Byte()
        Dim Result As Byte()
        Dim Res As String = ""
        Dim Tmp As String = ""

        Data = Encoding.ASCII.GetBytes(strString)
        Result = MD5.ComputeHash(Data)
        For i As Integer = 0 To Result.Length - 1
            Tmp = Hex(Result(i))
            If Len(Tmp) = 1 Then Tmp = "0" & Tmp
            Res += Tmp
        Next
        Return Res
    End Function
    Public Function CountPatches(ByVal s As String) As Integer
        Dim wc As New Net.WebClient
        Dim Content As Integer = wc.DownloadString(s).Split(vbNewLine).Length
        Return Content - 1
    End Function
End Class
