⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clsenskripsi.vb

📁 This is a Text Editor Created USing VB.net
💻 VB
字号:
Imports System.IO
Imports System.Text
Imports System.Security.Cryptography

Public Class clsEnskripsi

    Enum MetodeEnskripsi
        DES
        RC2
        Rijndael
    End Enum

    Private Function GetKeyByteArray(ByVal password As String) As Byte()
        Dim tmpbyte(7) As Byte
        password = password.PadRight(8)
        For i As Integer = 0 To 7
            tmpbyte(i) = Asc(Mid$(password, i + 1, 1))
        Next
        Return tmpbyte
    End Function

    Public Function Enskrip(ByVal plainText As String, ByVal password As String, Optional ByVal Metode As MetodeEnskripsi = MetodeEnskripsi.DES) As String
        On Error Resume Next
        Dim bytekey() As Byte = GetKeyByteArray(password)
        Dim byteIV() As Byte = GetKeyByteArray(StrReverse(password))
        Dim ToEncrypt As Byte() = Encoding.UTF8.GetBytes(plainText)
        Dim Encryptor As ICryptoTransform
        Select Case Metode
            Case MetodeEnskripsi.DES
                Dim Provider As New DESCryptoServiceProvider
                Encryptor = Provider.CreateEncryptor(bytekey, byteIV)
            Case MetodeEnskripsi.RC2
                Dim Provider As New RC2CryptoServiceProvider
                Encryptor = Provider.CreateEncryptor(bytekey, byteIV)
            Case Else
                byteIV = Encoding.ASCII.GetBytes("1234567890123456")
                Dim bSaltValue As Byte() = Encoding.ASCII.GetBytes("12")
                Dim pdbPassword As New PasswordDeriveBytes(password, bSaltValue, "SHA1", 2)
                bytekey = pdbPassword.GetBytes(256 / 8)
                Dim Provider As New RijndaelManaged()
                Encryptor = Provider.CreateEncryptor(bytekey, byteIV)
        End Select
        Dim msEncrypt As New MemoryStream()
        Dim csEncrypt As New CryptoStream(msEncrypt, Encryptor, CryptoStreamMode.Write)

        csEncrypt.Write(ToEncrypt, 0, ToEncrypt.Length)
        csEncrypt.FlushFinalBlock()

        Dim encrypted As Byte() = msEncrypt.ToArray()

        msEncrypt.Close()
        csEncrypt.Close()

        Return Convert.ToBase64String(encrypted)
    End Function

    Public Function Deskrip(ByVal plainText As String, ByVal password As String, Optional ByVal metode As MetodeEnskripsi = MetodeEnskripsi.DES) As String
        On Error Resume Next
        Dim bytekey() As Byte = GetKeyByteArray(password)
        Dim byteIV() As Byte = GetKeyByteArray(StrReverse(password))
        Dim encrypted As Byte() = Convert.FromBase64String(plainText)
        Dim Encryptor As ICryptoTransform

        Select Case metode
            Case MetodeEnskripsi.DES
                Dim Provider As New DESCryptoServiceProvider
                Encryptor = Provider.CreateDecryptor(bytekey, byteIV)
            Case MetodeEnskripsi.RC2
                Dim Provider As New RC2CryptoServiceProvider
                Encryptor = Provider.CreateDecryptor(bytekey, byteIV)
            Case Else
                byteIV = Encoding.ASCII.GetBytes("1234567890123456")
                Dim bSaltValue As Byte() = Encoding.ASCII.GetBytes("12")
                Dim pdbPassword As New PasswordDeriveBytes(password, bSaltValue, "SHA1", 2)
                bytekey = pdbPassword.GetBytes(256 / 8)
                Dim Provider As New RijndaelManaged
                Encryptor = Provider.CreateDecryptor(bytekey, byteIV)
        End Select

        Dim msEncrypt As New MemoryStream(encrypted)
        Dim csEncrypt As New CryptoStream(msEncrypt, Encryptor, CryptoStreamMode.Read)

        Dim ToDescrypt(encrypted.Length) As Byte
        Dim intDecryptedByte As Integer = csEncrypt.Read(ToDescrypt, 0, ToDescrypt.Length)

        msEncrypt.Close()
        csEncrypt.Close()

        Return Encoding.UTF8.GetString(ToDescrypt, 0, intDecryptedByte)
    End Function

End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -