Projects

Find all our projects in development below.
All source code is GNU General Public License (GPL)

Encrypto

Browsing clsSecurity.vb (2.16 KB)

Option Explicit On

Imports System.Text
Imports System.Collections.Specialized
Imports System.Security.Cryptography

Public Class clsSecurity

    Private lbtVector() As Byte = {240, 3, 45, 29, 0, 76, 173, 59}
    Private lscryptoKey As String = ""

    Public Sub New(ByVal cryptoKey As String)

        lscryptoKey = cryptoKey

    End Sub

    Public Function Decrypt(ByVal inString As String) As String

        Dim buffer() As Byte = {}
        Dim loCryptoClass As New TripleDESCryptoServiceProvider
        Dim loCryptoProvider As New MD5CryptoServiceProvider

        Try

            buffer = Convert.FromBase64String(inString)
            loCryptoClass.Key = loCryptoProvider.ComputeHash(ASCIIEncoding.ASCII.GetBytes(lscryptoKey))
            loCryptoClass.IV = lbtVector

            Return Encoding.ASCII.GetString(loCryptoClass.CreateDecryptor().TransformFinalBlock(buffer, 0, buffer.Length))

        Catch ex As Exception
            Throw ex
        Finally
            loCryptoClass.Clear()
            loCryptoProvider.Clear()
            loCryptoClass = Nothing
            loCryptoProvider = Nothing
        End Try

    End Function

    Public Function Encrypt(ByVal inString As String) As String

        Dim loCryptoClass As New TripleDESCryptoServiceProvider
        Dim loCryptoProvider As New MD5CryptoServiceProvider
        Dim lbtBuffer() As Byte = {}

        Try

            lbtBuffer = Encoding.ASCII.GetBytes(inString)
            loCryptoClass.Key = loCryptoProvider.ComputeHash(ASCIIEncoding.ASCII.GetBytes(lscryptoKey))
            loCryptoClass.IV = lbtVector
            inString = Convert.ToBase64String(loCryptoClass.CreateEncryptor().TransformFinalBlock(lbtBuffer, 0, lbtBuffer.Length))

            Return inString

        Catch ex As CryptographicException
            Throw ex
        Catch ex As FormatException
            Throw ex
        Catch ex As Exception
            Throw ex
        Finally
            loCryptoClass.Clear()
            loCryptoProvider.Clear()
            loCryptoClass = Nothing
            loCryptoProvider = Nothing
        End Try

    End Function

End Class

Download clsSecurity.vb

Back to file list


Back to project page