1、添加命名空间,空间缩写为sur, sur可以随便取,但是要和代码保持一致:
此主题相关图片如下:001.jpg
2、将下面的修改后的代码复制到foxtable的全局代码中,注意加粗的:
Public Function Encrypt(ByVal pToEncrypt As String, ByVal sKey As String) As String
Dim DES As New sur.DESCryptoServiceProvider()
Dim inputByteArray() As Byte
inputByteArray = Encoding.Default.GetBytes(pToEncrypt)
''建立加密对象的密钥和偏移量
''原文使用ASCIIEncoding.ASCII方法的GetBytes方法
''使得输入密码必须输入英文文本
DES.Key = ASCIIEncoding.ASCII.GetBytes(sKey)
DES.IV = ASCIIEncoding.ASCII.GetBytes(sKey)
''写二进制数组到加密流
''(把内存流中的内容全部写入)
Dim ms As New System.IO.MemoryStream()
Dim cs As New sur.CryptoStream(ms, DES.CreateEncryptor, sur.CryptoStreamMode.Write)
''写二进制数组到加密流
''(把内存流中的内容全部写入)
cs.Write(inputByteArray, 0, inputByteArray.Length)
cs.FlushFinalBlock()
''建立输出字符串
Dim ret As New StringBuilder()
Dim b As Byte
For Each b In ms.ToArray()
ret.AppendFormat("", b)
Next
Return ret.ToString()
End Function
Public Function Decrypt(ByVal pToDecrypt As String, ByVal sKey As String) As String
Dim DES As New sur.DESCryptoServiceProvider()
''把字符串放入byte数组
Dim len As Integer
len = pToDecrypt.Length / 2 - 1
Dim inputByteArray(len) As Byte
Dim x, i As Integer
For x = 0 To len
i = Convert.ToInt32(pToDecrypt.Substring(x * 2, 2), 16)
inputByteArray(x) = CType(i, Byte)
Next
''建立加密对象的密钥和偏移量,此值重要,不能修改
DES.Key = ASCIIEncoding.ASCII.GetBytes(sKey)
DES.IV = ASCIIEncoding.ASCII.GetBytes(sKey)
Dim ms As New System.IO.MemoryStream()
Dim cs As New sur.CryptoStream(ms, DES.CreateDecryptor, sur.CryptoStreamMode.Write)
cs.Write(inputByteArray, 0, inputByteArray.Length)
cs.FlushFinalBlock()
Return Encoding.Default.GetString(ms.ToArray)
End Function