精华内容
下载资源
问答
  • VB6 加密解密字符串
    千次阅读
    2019-01-22 17:59:00
    Public Function EnCodeStr(ByVal password As String) As String
        Dim il_bit, il_x, il_y, il_z, il_len, i               As Long
        Dim is_out     As String
        il_len = Len(password)
        il_x = 0
        il_y = 0
        is_out = ""
        For i = 1 To il_len
                il_bit = AscW(Mid(password, i, 1))
                il_y = (il_bit * 13 Mod 256) + il_x
                is_out = is_out & ChrW(Fix(il_y))
                il_x = il_bit * 13 / 256
        Next
        is_out = is_out & ChrW(Fix(il_x))
        password = is_out
        il_len = Len(password)
        il_x = 0
        il_y = 0
        is_out = ""
        For i = 1 To il_len
                il_bit = AscW(Mid(password, i, 1))
                il_y = il_bit / 16 + 64
                is_out = is_out & ChrW(Fix(il_y))
                il_y = (il_bit Mod 16) + 64
                is_out = is_out & ChrW(Fix(il_y))
        Next
        EnCodeStr = is_out
    End Function
    
    Public Function DeCodeStr(ByVal password As String) As String
        Dim is_out     As String
        Dim il_x, il_y, il_len, i, il_bit             As Long
        
        il_len = Len(password)
        il_x = 0
        il_y = 0
        is_out = ""
        For i = 1 To il_len Step 2
                il_bit = AscW(Mid(password, i, 1))
                il_y = (il_bit - 64) * 16
                il_y = il_y + AscW(Mid(password, i + 1, 1)) - 64
                is_out = is_out & ChrW(il_y)
        Next
        
        il_x = 0
        il_y = 0
        password = is_out
        is_out = ""
        
        il_len = Len(password)
        il_x = AscW(Mid(password, il_len, 1))
        
        For i = (il_len - 1) To 1 Step -1
                il_y = il_x * 256 + AscW(Mid(password, i, 1))
                il_x = il_y Mod 13
                is_out = ChrW(Fix(il_y / 13)) & is_out
        Next
        DeCodeStr = is_out
    End Function
    

      

    转载于:https://www.cnblogs.com/wgscd/p/10305200.html

    更多相关内容
  • VB加密解密字符串

    2018-02-27 17:36:41
    Dim o Dim str as string Set o = CreateObject("MyEncrypt.DES") str = o.Encrypt("加密的明文", "8位数密匙(记住要用于解密)") str = o.Decrypt("解密的密文", "8位数密匙(加密时的密匙)")
  • VB 加密解密模块

    2018-08-29 00:49:33
    VB6 加密解密模块: 加密(字符串,密码)解密(字符串,密码) 加密和解密的密码要一至。
  • VB加密解密源码

    2013-12-24 16:05:04
    API MD5算法 CODE MD5算法 DLL调用DM5算法 顶级的ASE加密解密算法
  • vb 加密解密模块

    2019-07-30 13:39:42
    Function cipher(stext As String) '密码加密程序 Const min_asc = 32 Const max_asc = 126 Const num_asc = max_asc - min_asc + 1 Dim offset As Long Dim strlen As Integer Dim i ...
    Function cipher(stext As String)    '密码加密程序
        Const min_asc = 32
        Const max_asc = 126
        Const num_asc = max_asc - min_asc + 1
        Dim offset As Long
        Dim strlen As Integer
        Dim i As Integer
        Dim ch As Integer
        Dim ptext As String
        offset = 123
        Rnd (-1)
        Randomize (offset)
        strlen = Len(stext)
        For i = 1 To strlen
           ch = Asc(Mid(stext, i, 1))
           If ch >= min_asc And ch <= max_asc Then
               ch = ch - min_asc
               offset = Int((num_asc + 1) * Rnd())
               ch = ((ch + offset) Mod num_asc)
               ch = ch + min_asc
               ptext = ptext & Chr(ch)
           End If
        Next i
        cipher = ptext
    End Function
    Function decipher(stext As String)      '密码解密程序
        Const min_asc = 32 '最小ASCII码
        Const max_asc = 126 '最大ASCII码 字符
        Const num_asc = max_asc - min_asc + 1
        Dim offset As Long
        Dim strlen As Integer
        Dim i As Integer
        Dim ch As Integer
        Dim ptext As String
        offset = 123
        Rnd (-1)
        Randomize (offset)
        strlen = Len(stext)
        For i = 1 To strlen
           ch = Asc(Mid(stext, i, 1)) '取字母转变成ASCII码
           If ch >= min_asc And ch <= max_asc Then
               ch = ch - min_asc
               offset = Int((num_asc + 1) * Rnd())
               ch = ((ch - offset) Mod num_asc)
               If ch < 0 Then
                   ch = ch + num_asc
               End If
               ch = ch + min_asc
               ptext = ptext & Chr(ch)
           End If
        Next i
        decipher = ptext
    End Function

    转载于:https://www.cnblogs.com/any-time-any-place/archive/2012/11/07/2758547.html

    展开全文
  • VB加密解密

    2013-03-27 06:10:42
    加密解密本程序在 Windows98SE+VB5.0 中运行通过
  • vb加密解密

    2012-01-15 21:18:12
    vb加密解密,一种简单有效的加密解密代码
  • 一个简单实用的VB字符串加密解密程序,可以是文本或字符,加密效果好,速度快,安全性高,而且代码易用易学,程序中还使用到了一个XP风格的进度条控件,VB新手朋友正好也可以研究一下进度条的使用。运行效果如演示...
  • 21种VB加密/解密算法源代码,另外还有50多种种压缩/解压算法源码,相信够你用了,觉得还不错吧,推荐给大家。
  • VB.NET实现AES加密解密

    2017-08-22 17:49:27
    VB.NET实现AES加密解密代码,可直接使用
  • VB加密解密算法

    2012-06-03 09:32:16
    VB加密解密算法,VB编程原码,用于用户制作程序加密内容
  • 没什么技术含量,供菜鸟学习 高手走开 嘿嘿
  • 本源码演示VB6.0实现的文件双重加密解密功能,注意,在本程序中,把已经加密的文件再次加密即是解密,测试时候加密文件 / 解密文件试一下。加密核心类请参考源码中的modCrypt.bas类文件。
  • 应用程序连接远程oracle数据库时,从配置文件.INI中读取用户名及密码,对于密码的加密解密,采用DES加密算法。 database.ini文件格式 [database] username=ua password=CBF1DE02851D0E333F1F47B90C9A2442
  • 加密 解密字符串的例子加密 解密字符串的例子加密 解密字符串的例子加密 解密字符串的例子
  • 一个经典的vb。net加密解密源代码,可以给初学者学习参考之用。
  • VB6.0 RSA/AES/Md5/Base64加密 解密 微信小程序 javascript 通用 仅demo实例!可先测试使用!
  • vb.net加密解密源代码

    2012-12-05 20:51:05
    自己做的一个加密解密小程序,采用vs2008编写,保证有效
  • VB字符串加密解密

    2021-05-12 18:20:40
    摘要:VB源码,加密解密,字符串加密 VB字符串加密解密,形式简单,代码简洁,便于学习,输入需要加密的字符串后,点击“加密”即可,也可以点击“解密”还原。最后可以清屏。
  • vb.net DES加密解密

    2021-02-07 15:14:05
    1、DES加密 Public Function EncryptDes(ByVal SourceStr As String, Optional ByVal myKey As String = "", Optional ByVal myIV As String = "") As String '使用的DES对称加密 If String.IsNullOrEmpty(myKey) ...

    1、DES加密

    Public Function EncryptDes(ByVal SourceStr As String, Optional ByVal myKey As String = "", Optional ByVal myIV As String = "") As String '使用的DES对称加密
            If String.IsNullOrEmpty(myKey) Then
                myKey = Me.JMKey
            End If
            If String.IsNullOrEmpty(myIV) Then
                myIV = Me.JMIv
            End If
            Dim des As New System.Security.Cryptography.DESCryptoServiceProvider 'DES算法
            'Dim DES As New System.Security.Cryptography.TripleDESCryptoServiceProvider'TripleDES算法
            Dim inputByteArray As Byte()
            inputByteArray = System.Text.Encoding.Default.GetBytes(SourceStr)
            des.Key = System.Text.Encoding.UTF8.GetBytes(myKey) 'myKey DES用8个字符,TripleDES要24个字符
            des.IV = System.Text.Encoding.UTF8.GetBytes(myIV) 'myIV DES用8个字符,TripleDES要24个字符
            Dim ms As New System.IO.MemoryStream
            Dim cs As New System.Security.Cryptography.CryptoStream(ms, des.CreateEncryptor(), System.Security.Cryptography.CryptoStreamMode.Write)
            Dim sw As New System.IO.StreamWriter(cs)
            sw.Write(SourceStr)
            sw.Flush()
            cs.FlushFinalBlock()
            ms.Flush()
            Return Convert.ToBase64String(ms.GetBuffer(), 0, ms.Length)
        End Function
    2、DES解密
    
    Public Function DecryptDes(ByVal SourceStr As String, Optional ByVal myKey As String = "", Optional ByVal myIV As String = "") As String    '使用标准DES对称解密
            If String.IsNullOrEmpty(SourceStr) Then
                Return SourceStr
            End If
            If SourceStr = "" Then
                Return SourceStr
            End If
            If String.IsNullOrEmpty(myKey) Then
                myKey = Me.JMKey
            End If
            If String.IsNullOrEmpty(myIV) Then
                myIV = Me.JMIv
            End If
            Dim des As New System.Security.Cryptography.DESCryptoServiceProvider 'DES算法
            'Dim DES As New System.Security.Cryptography.TripleDESCryptoServiceProvider'TripleDES算法
            des.Key = System.Text.Encoding.UTF8.GetBytes(myKey) 'myKey DES用8个字符,TripleDES要24个字符
            des.IV = System.Text.Encoding.UTF8.GetBytes(myIV) 'myIV DES用8个字符,TripleDES要24个字符
            Dim buffer As Byte() = Convert.FromBase64String(SourceStr)
            Dim ms As New System.IO.MemoryStream(buffer)
            Dim cs As New System.Security.Cryptography.CryptoStream(ms, des.CreateDecryptor(), System.Security.Cryptography.CryptoStreamMode.Read)
            Dim sr As New System.IO.StreamReader(cs)
            DecryptDes = sr.ReadToEnd()
            Return DecryptDes
        End Function
    

    请注意: 不同的加密方式,密钥长vb.net教程度有要求; 密钥可以写入配置文件中,定期调整;

    展开全文
  • 内容索引:VB源码,加密解密,加密,解密 一个简单的VB加密、解密程序,加、解密的主要对象是文本或字符,加密效果好,速度快,安全性高,而且代码易用易学,程序中还使用到了一个XP风格的进度条控件,VB新手朋友正好也...
  • 该程序是在VB6.0的基础上开发的,支持数据的加密解密,还有可以对文件进行加密解密。用户可以根据自己的密钥进行个性化的加密解密
  • VB U盘加密 解密.rar

    2019-07-10 11:50:44
    VB U盘加密 解密,俗称“U盘加密器”,防止病毒入侵,本USB加密程序采用国际上最简陋的加密技术,一旦加密后要解密才能用!不过防止病毒入侵的有效力度为100%!加密后需要使用此工具解密才能使用U盘。
  • VB6.0加密解密

    2018-02-27 17:40:45
    使用cmd进入以下路径调用RegAsm.exe使用以下的命令 \Microsoft.NET\Framework\v4.0.30319 ... regasm myTest.dll 下面的命令生成包含所有必要的注册表项的 myTest.reg 文件。 此命令不更新注册表。...
  • 加密解密

    2017-08-22 11:47:39
    加密解密帮助类
  • c++ rc4代码,可以编译可以用。很小的DEMO 学习用
  • 由于没有人能够提供功能齐全的BI-DIRECTIONAL解决方案,我已经冒昧地在本文中为社区提供了一个解决方案....以下是使用Triple DES加密数据的COMPLETE解决方案,其方式与.NET和PHP兼容,允许双向三重DES加...

    由于没有人能够提供功能齐全的BI-DIRECTIONAL解决方案,我已经冒昧地在本文中为社区提供了一个解决方案.

    问题是,PHP不符合标准,强制填充字符串以便匹配.目前,如果在.NET和PHP之间随机生成,没有已知的方法可靠地传递IV(如果你确实发现了如何或者这种变化,请随时修改它).

    以下是使用Triple DES加密数据的COMPLETE解决方案,其方式与.NET和PHP兼容,允许双向三重DES加密通信.此方法也与Java,Delphi,Objective-C和许多其他语言兼容,但此类代码不会在此处提供,因为这不是已发布问题的解决方案.

    VB.NET Triple DES Class

    Imports System

    Imports System.Text

    Imports System.IO

    Imports System.Security.Cryptography

    Public Class TripleDES

    Private bPassword As Byte()

    Private sPassword As String

    Public Sub New(Optional ByVal Password As String = "password")

    ' On Class Begin

    Me.Password = Password

    End Sub

    Public ReadOnly Property PasswordHash As String

    Get

    Dim UTF8 As System.Text.UTF8Encoding = New System.Text.UTF8Encoding

    Return UTF8.GetString(bPassword)

    End Get

    End Property

    Public Property Password() As String

    Get

    Dim UTF8 As System.Text.UTF8Encoding = New System.Text.UTF8Encoding

    Return sPassword

    End Get

    Set(value As String)

    Dim UTF8 As System.Text.UTF8Encoding = New System.Text.UTF8Encoding

    Dim HashProvider As MD5CryptoServiceProvider = New MD5CryptoServiceProvider()

    bPassword = HashProvider.ComputeHash(UTF8.GetBytes(value))

    sPassword = value

    End Set

    End Property

    #Region "Encrypt"

    ' Encrypt using Password from Property Set (pre-hashed)

    Public Function Encrypt(ByVal Message As String) As String

    Dim Results() As Byte

    Dim UTF8 As System.Text.UTF8Encoding = New System.Text.UTF8Encoding

    Using HashProvider As MD5CryptoServiceProvider = New MD5CryptoServiceProvider()

    Dim TDESKey() As Byte = bPassword

    Using TDESAlgorithm As TripleDESCryptoServiceProvider = New TripleDESCryptoServiceProvider() With {.Key = TDESKey, .Mode = CipherMode.ECB, .Padding = PaddingMode.PKCS7}

    Dim DataToEncrypt() As Byte = UTF8.GetBytes(Message)

    Try

    Dim Encryptor As ICryptoTransform = TDESAlgorithm.CreateEncryptor

    Results = Encryptor.TransformFinalBlock(DataToEncrypt, 0, DataToEncrypt.Length)

    Finally

    TDESAlgorithm.Clear()

    HashProvider.Clear()

    End Try

    End Using

    End Using

    Return Convert.ToBase64String(Results)

    End Function

    ' Encrypt using Password as byte array

    Private Function Encrypt(ByVal Message As String, ByVal Password() As Byte) As String

    Dim Results() As Byte

    Dim UTF8 As System.Text.UTF8Encoding = New System.Text.UTF8Encoding

    Using HashProvider As MD5CryptoServiceProvider = New MD5CryptoServiceProvider()

    Dim TDESKey() As Byte = HashProvider.ComputeHash(UTF8.GetBytes(UTF8.GetString(Password)))

    Using TDESAlgorithm As TripleDESCryptoServiceProvider = New TripleDESCryptoServiceProvider() With {.Key = TDESKey, .Mode = CipherMode.ECB, .Padding = PaddingMode.PKCS7}

    Dim DataToEncrypt() As Byte = UTF8.GetBytes(Message)

    Try

    Dim Encryptor As ICryptoTransform = TDESAlgorithm.CreateEncryptor

    Results = Encryptor.TransformFinalBlock(DataToEncrypt, 0, DataToEncrypt.Length)

    Finally

    TDESAlgorithm.Clear()

    HashProvider.Clear()

    End Try

    End Using

    End Using

    Return Convert.ToBase64String(Results)

    End Function

    ' Encrypt using Password as string

    Public Function Encrypt(ByVal Message As String, ByVal Password As String) As String

    Dim Results() As Byte

    Dim UTF8 As System.Text.UTF8Encoding = New System.Text.UTF8Encoding

    ' Step 1. We hash the Passphrase using MD5

    ' We use the MD5 hash generator as the result is a 128 bit byte array

    ' which is a valid length for the Triple DES encoder we use below

    Using HashProvider As MD5CryptoServiceProvider = New MD5CryptoServiceProvider()

    Dim TDESKey() As Byte = HashProvider.ComputeHash(UTF8.GetBytes(Password))

    ' Step 2. Create a new TripleDESCryptoServiceProvider object

    ' Step 3. Setup the encoder

    Using TDESAlgorithm As TripleDESCryptoServiceProvider = New TripleDESCryptoServiceProvider() With {.Key = TDESKey, .Mode = CipherMode.ECB, .Padding = PaddingMode.PKCS7}

    ' Step 4. Convert the input string to a byte[]

    Dim DataToEncrypt() As Byte = UTF8.GetBytes(Message)

    ' Step 5. Attempt to encrypt the string

    Try

    Dim Encryptor As ICryptoTransform = TDESAlgorithm.CreateEncryptor

    Results = Encryptor.TransformFinalBlock(DataToEncrypt, 0, DataToEncrypt.Length)

    Finally

    ' Clear the Triple Des and Hashprovider services of any sensitive information

    TDESAlgorithm.Clear()

    HashProvider.Clear()

    End Try

    End Using

    End Using

    ' Step 6. Return the encrypted string as a base64 encoded string

    Return Convert.ToBase64String(Results)

    End Function

    #End Region

    #Region "Decrypt"

    ' Decrypt using Password from Property (pre-hashed)

    Public Function Decrypt(ByVal Message As String) As String

    Dim Results() As Byte

    Dim UTF8 As System.Text.UTF8Encoding = New System.Text.UTF8Encoding

    Using HashProvider As MD5CryptoServiceProvider = New MD5CryptoServiceProvider()

    Dim TDESKey() As Byte = Me.bPassword

    Using TDESAlgorithm As TripleDESCryptoServiceProvider = New TripleDESCryptoServiceProvider() With {.Key = TDESKey, .Mode = CipherMode.ECB, .Padding = PaddingMode.PKCS7}

    Dim DataToDecrypt() As Byte = Convert.FromBase64String(Message)

    Try

    Dim Decryptor As ICryptoTransform = TDESAlgorithm.CreateDecryptor

    Results = Decryptor.TransformFinalBlock(DataToDecrypt, 0, DataToDecrypt.Length)

    Finally

    TDESAlgorithm.Clear()

    HashProvider.Clear()

    End Try

    End Using

    End Using

    Return UTF8.GetString(Results)

    End Function

    ' Decrypt using Password as Byte array

    Public Function Decrypt(ByVal Message As String, ByVal Password() As Byte) As String

    Dim Results() As Byte

    Dim UTF8 As System.Text.UTF8Encoding = New System.Text.UTF8Encoding

    Using HashProvider As MD5CryptoServiceProvider = New MD5CryptoServiceProvider()

    Dim TDESKey() As Byte = HashProvider.ComputeHash(UTF8.GetBytes(UTF8.GetString(Password)))

    Using TDESAlgorithm As TripleDESCryptoServiceProvider = New TripleDESCryptoServiceProvider() With {.Key = TDESKey, .Mode = CipherMode.ECB, .Padding = PaddingMode.PKCS7}

    Dim DataToDecrypt() As Byte = Convert.FromBase64String(Message)

    Try

    Dim Decryptor As ICryptoTransform = TDESAlgorithm.CreateDecryptor

    Results = Decryptor.TransformFinalBlock(DataToDecrypt, 0, DataToDecrypt.Length)

    Finally

    TDESAlgorithm.Clear()

    HashProvider.Clear()

    End Try

    End Using

    End Using

    Return UTF8.GetString(Results)

    End Function

    ' Decrypt using Password as string

    Public Function Decrypt(ByVal Message As String, ByVal Password As String) As String

    Dim Results() As Byte

    Dim UTF8 As System.Text.UTF8Encoding = New System.Text.UTF8Encoding

    ' Step 1. We hash the pass phrase using MD5

    ' We use the MD5 hash generator as the result is a 128-bit byte array

    ' which is a valid length for the Triple DES encoder we use below

    Using HashProvider As MD5CryptoServiceProvider = New MD5CryptoServiceProvider()

    Dim TDESKey() As Byte = HashProvider.ComputeHash(UTF8.GetBytes(Password))

    ' Step 2. Create a new TripleDESCryptoServiceProvider object

    ' Step 3. Setup the decoder

    Using TDESAlgorithm As TripleDESCryptoServiceProvider = New TripleDESCryptoServiceProvider() With {.Key = TDESKey, .Mode = CipherMode.ECB, .Padding = PaddingMode.PKCS7}

    ' Step 4. Convert the input string to a byte[]

    Dim DataToDecrypt() As Byte = Convert.FromBase64String(Message)

    ' Step 5. Attempt to decrypt the string

    Try

    Dim Decryptor As ICryptoTransform = TDESAlgorithm.CreateDecryptor

    Results = Decryptor.TransformFinalBlock(DataToDecrypt, 0, DataToDecrypt.Length)

    Finally

    ' Clear the Triple Des and Hash provider services of any sensitive information

    TDESAlgorithm.Clear()

    HashProvider.Clear()

    End Try

    End Using

    End Using

    ' Step 6. Return the decrypted string in UTF8 format

    Return UTF8.GetString(Results)

    End Function

    #End Region

    End Class

    VB.NET Triple DES类用法

    Dim tdes As New TripleDES("12345")

    Dim vbEncrypted = tdes.Encrypt("Encrypted using VB.NET")

    Dim phpEncrypted = "5Ittyr0+jiI7QQmPrvSVnMc9MEWQCjAN"

    Debug.Print("PHP Encrypted: " & phpEncrypted)

    Debug.Print("VB Encrypted: " & vbEncrypted)

    Debug.Print("PHP Encrypted (decrypted result): " & tdes.Decrypt(phpEncrypted))

    Debug.Print("VB Encrypted (decrypted result): " & tdes.Decrypt(vbEncrypted))

    PHP三重DES类

    class TripleDES {

    private $bPassword;

    private $sPassword;

    function __construct($Password) {

    $this->bPassword = md5(utf8_encode($Password),TRUE);

    $this->bPassword .= substr($this->bPassword,0,8);

    $this->sPassword - $Password;

    }

    function Password($Password = "") {

    if($Password == "") {

    return $this->sPassword;

    } else {

    $this->bPassword = md5(utf8_encode($Password),TRUE);

    $this->bPassword .= substr($this->bPassword,0,8);

    $this->sPassword - $Password;

    }

    }

    function PasswordHash() {

    return $this->bPassword;

    }

    function Encrypt($Message, $Password = "") {

    if($Password <> "") { $this->Password($Password); }

    $size=mcrypt_get_block_size('tripledes','ecb');

    $padding=$size-((strlen($Message)) % $size);

    $Message .= str_repeat(chr($padding),$padding);

    $encrypt = mcrypt_encrypt('tripledes',$this->bPassword,$Message,'ecb');

    return base64_encode($encrypt);

    }

    function Decrypt($message, $Password = "") {

    if($Password <> "") { $this->Password($Password); }

    return trim(mcrypt_decrypt('tripledes', $this->bPassword, base64_decode($message), 'ecb'), ord(2));

    }

    }

    PHP Triple DES类用法

    $tdes = new TripleDES("12345");

    $phpEncrypted = $tdes->encrypt("Encrypted using PHP");

    $vbEncrypted = "5Ittyr0+jiI7QQmPrvSVnP3s2CeoTJmF"; // Encrypted using VB.NET

    echo "PHP Encrypted: " . $phpEncrypted . '
    ';

    echo "VB Encrypted: " . $vbEncrypted . '
    ';

    echo "PHP Encrypted (decrypted result): " . $tdes->Decrypt($phpEncrypted) . '
    ';

    echo "VB Encrypted (decrypted result): " . $tdes->Decrypt($vbEncrypted) . '
    ';

    我尽我所能使两个类的可用性水平相同,因为语言自然允许.由于PHP不允许重载函数,我不得不使用密码作为可选参数,这是一个字符串值. VB.NET解决方案有一个额外的覆盖,允许您在加密/解密函数上传递密码字符串的字节值.提供示例代码以显示每个的用法,显示了实例化对象的最简单形式,两个类都允许在对象创建时设置密码.

    对于其他任何人都在抨击他们的大脑试图找到一个三重DES的工作双向解决方案(并且不想被强制进入每个人似乎指向的方框 – Rijndael),那么这个解决方案是为你,你可以不停地撞到墙上.

    添加了VB.NET TripleDES类的C#转换

    C#类(已添加[2017-01-11])

    using System;

    using System.Security.Cryptography;

    public class TripleDES {

    private byte[] bPassword;

    private string sPassword;

    public TripleDES( string Password = "password" ) {

    // On Class Begin

    this.Password = Password;

    }

    public string PasswordHash {

    get {

    System.Text.UTF8Encoding UTF8 = new System.Text.UTF8Encoding();

    return UTF8.GetString( bPassword );

    }

    }

    public string Password {

    get {

    System.Text.UTF8Encoding UTF8 = new System.Text.UTF8Encoding();

    return sPassword;

    }

    set {

    System.Text.UTF8Encoding UTF8 = new System.Text.UTF8Encoding();

    MD5CryptoServiceProvider HashProvider = new MD5CryptoServiceProvider();

    bPassword = HashProvider.ComputeHash( UTF8.GetBytes( value ) );

    sPassword = value;

    }

    }

    #region "Encrypt"

    // Encrypt using Password from Property Set (pre-hashed)

    public string Encrypt( string Message ) {

    byte[] Results = null;

    System.Text.UTF8Encoding UTF8 = new System.Text.UTF8Encoding();

    using ( MD5CryptoServiceProvider HashProvider = new MD5CryptoServiceProvider() ) {

    byte[] TDESKey = bPassword;

    using ( TripleDESCryptoServiceProvider TDESAlgorithm = new TripleDESCryptoServiceProvider { Key = TDESKey, Mode = CipherMode.ECB, Padding = PaddingMode.PKCS7 } ) {

    byte[] DataToEncrypt = UTF8.GetBytes( Message );

    try {

    ICryptoTransform Encryptor = TDESAlgorithm.CreateEncryptor();

    Results = Encryptor.TransformFinalBlock( DataToEncrypt, 0, DataToEncrypt.Length );

    } finally {

    TDESAlgorithm.Clear();

    HashProvider.Clear();

    }

    }

    }

    return Convert.ToBase64String( Results );

    }

    // Encrypt using Password as byte array

    private string Encrypt( string Message, byte[] Password ) {

    byte[] Results = null;

    System.Text.UTF8Encoding UTF8 = new System.Text.UTF8Encoding();

    using ( MD5CryptoServiceProvider HashProvider = new MD5CryptoServiceProvider() ) {

    byte[] TDESKey = HashProvider.ComputeHash( UTF8.GetBytes( UTF8.GetString( Password ) ) );

    using ( TripleDESCryptoServiceProvider TDESAlgorithm = new TripleDESCryptoServiceProvider { Key = TDESKey, Mode = CipherMode.ECB, Padding = PaddingMode.PKCS7 } ) {

    byte[] DataToEncrypt = UTF8.GetBytes( Message );

    try {

    ICryptoTransform Encryptor = TDESAlgorithm.CreateEncryptor();

    Results = Encryptor.TransformFinalBlock( DataToEncrypt, 0, DataToEncrypt.Length );

    } finally {

    TDESAlgorithm.Clear();

    HashProvider.Clear();

    }

    }

    }

    return Convert.ToBase64String( Results );

    }

    // Encrypt using Password as string

    public string Encrypt( string Message, string Password ) {

    byte[] Results = null;

    System.Text.UTF8Encoding UTF8 = new System.Text.UTF8Encoding();

    // Step 1. We hash the Passphrase using MD5

    // We use the MD5 hash generator as the result is a 128 bit byte array

    // which is a valid length for the Triple DES encoder we use below

    using ( MD5CryptoServiceProvider HashProvider = new MD5CryptoServiceProvider() ) {

    byte[] TDESKey = HashProvider.ComputeHash( UTF8.GetBytes( Password ) );

    // Step 2. Create a new TripleDESCryptoServiceProvider object

    // Step 3. Setup the encoder

    using ( TripleDESCryptoServiceProvider TDESAlgorithm = new TripleDESCryptoServiceProvider { Key = TDESKey, Mode = CipherMode.ECB, Padding = PaddingMode.PKCS7 } ) {

    // Step 4. Convert the input string to a byte[]

    byte[] DataToEncrypt = UTF8.GetBytes( Message );

    // Step 5. Attempt to encrypt the string

    try {

    ICryptoTransform Encryptor = TDESAlgorithm.CreateEncryptor();

    Results = Encryptor.TransformFinalBlock( DataToEncrypt, 0, DataToEncrypt.Length );

    } finally {

    // Clear the Triple Des and Hashprovider services of any sensitive information

    TDESAlgorithm.Clear();

    HashProvider.Clear();

    }

    }

    }

    // Step 6. Return the encrypted string as a base64 encoded string

    return Convert.ToBase64String( Results );

    }

    #endregion

    #region "Decrypt"

    // Decrypt using Password from Property (pre-hashed)

    public string Decrypt( string Message ) {

    byte[] Results = null;

    System.Text.UTF8Encoding UTF8 = new System.Text.UTF8Encoding();

    using ( MD5CryptoServiceProvider HashProvider = new MD5CryptoServiceProvider() ) {

    byte[] TDESKey = this.bPassword;

    using ( TripleDESCryptoServiceProvider TDESAlgorithm = new TripleDESCryptoServiceProvider { Key = TDESKey, Mode = CipherMode.ECB, Padding = PaddingMode.PKCS7 } ) {

    byte[] DataToDecrypt = Convert.FromBase64String( Message );

    try {

    ICryptoTransform Decryptor = TDESAlgorithm.CreateDecryptor();

    Results = Decryptor.TransformFinalBlock( DataToDecrypt, 0, DataToDecrypt.Length );

    } finally {

    TDESAlgorithm.Clear();

    HashProvider.Clear();

    }

    }

    }

    return UTF8.GetString( Results );

    }

    // Decrypt using Password as Byte array

    public string Decrypt( string Message, byte[] Password ) {

    byte[] Results = null;

    System.Text.UTF8Encoding UTF8 = new System.Text.UTF8Encoding();

    using ( MD5CryptoServiceProvider HashProvider = new MD5CryptoServiceProvider() ) {

    byte[] TDESKey = HashProvider.ComputeHash( UTF8.GetBytes( UTF8.GetString( Password ) ) );

    using ( TripleDESCryptoServiceProvider TDESAlgorithm = new TripleDESCryptoServiceProvider { Key = TDESKey, Mode = CipherMode.ECB, Padding = PaddingMode.PKCS7 } ) {

    byte[] DataToDecrypt = Convert.FromBase64String( Message );

    try {

    ICryptoTransform Decryptor = TDESAlgorithm.CreateDecryptor();

    Results = Decryptor.TransformFinalBlock( DataToDecrypt, 0, DataToDecrypt.Length );

    } finally {

    TDESAlgorithm.Clear();

    HashProvider.Clear();

    }

    }

    }

    return UTF8.GetString( Results );

    }

    // Decrypt using Password as string

    public string Decrypt( string Message, string Password ) {

    byte[] Results = null;

    System.Text.UTF8Encoding UTF8 = new System.Text.UTF8Encoding();

    // Step 1. We hash the pass phrase using MD5

    // We use the MD5 hash generator as the result is a 128-bit byte array

    // which is a valid length for the Triple DES encoder we use below

    using ( MD5CryptoServiceProvider HashProvider = new MD5CryptoServiceProvider() ) {

    byte[] TDESKey = HashProvider.ComputeHash( UTF8.GetBytes( Password ) );

    // Step 2. Create a new TripleDESCryptoServiceProvider object

    // Step 3. Setup the decoder

    using ( TripleDESCryptoServiceProvider TDESAlgorithm = new TripleDESCryptoServiceProvider { Key = TDESKey, Mode = CipherMode.ECB, Padding = PaddingMode.PKCS7 } ) {

    // Step 4. Convert the input string to a byte[]

    byte[] DataToDecrypt = Convert.FromBase64String( Message );

    // Step 5. Attempt to decrypt the string

    try {

    ICryptoTransform Decryptor = TDESAlgorithm.CreateDecryptor();

    Results = Decryptor.TransformFinalBlock( DataToDecrypt, 0, DataToDecrypt.Length );

    } finally {

    // Clear the Triple Des and Hash provider services of any sensitive information

    TDESAlgorithm.Clear();

    HashProvider.Clear();

    }

    }

    }

    // Step 6. Return the decrypted string in UTF8 format

    return UTF8.GetString( Results );

    }

    #endregion

    }

    展开全文
  • 目前最高支持10位加密..可以自己在继续发挥..
  • 收集一些运行于VB环境的Blowfish Gost RC4等加密解密算法示例,都是一些比较常用且经典的VB6加密解密算法示例,同时适用于VB.NET编程,一共有将近10种的算法集中到了一个程序中演示,你在加密测试的时候可以选择任一...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 5,335
精华内容 2,134
关键字:

VB加密解密