简单好用的VB字符串加密解密函数

Private Function Encrypt(ByVal StrSource As String) As String    '加密     Dim BLowData As Byte     Dim BHigData As Byte     Dim i As Long     Dim k As Integer     Dim StrEncrypt As String     Dim StrChar As String     Dim KeyTemp As String     Dim Key1 As Byte

    For k = 1 To 30         KeyTemp = KeyTemp & CStr(Int(Rnd * (9) + 1))     Next         Key1 = CByte(Mid(KeyTemp, 11, 1) & Mid(KeyTemp, 27, 1))     For i = 1 To Len(StrSource)           StrChar = Mid(StrSource, i, 1)  '从待加密字符串中取出一个字符           BLowData = AscB(MidB(StrChar, 1, 1)) Xor Key1    '取字符的低字节和Key1进行异或运算           SHigData = AscB(MidB(StrChar, 2, 1))   '取字符的高字节           StrEncrypt = StrEncrypt & ChrB(BLowData) & ChrB(BHigData)    '将运算后的数据合成新的字符            Next i     Encrypt = KeyTemp & StrEncrypt

End Function

 

Private Function Decrypt(ByVal StrSource As String) As String     '解密     Dim BLowData As Byte     Dim BHigData As Byte     Dim i As Long     Dim k As Integer     Dim StrDecrypt As String     Dim StrChar As String     Dim KeyTemp As String

    Dim Key1 As Byte     KeyTemp = Mid(StrSource, 1, 30)         Key1 = CByte(Mid(KeyTemp, 11, 1) & Mid(KeyTemp, 27, 1))     For i = 31 To Len(StrSource)                 StrChar = Mid(StrSource, i, 1)    '从待解密字符串中取出一个字符          BLowData = AscB(MidB(StrChar, 1, 1)) Xor Key1   '取字符的低字节和Key1进行异或运算          BHigData = AscB(MidB(StrChar, 2, 1))      '取字符的高字节          StrDecrypt = StrDecrypt & ChrB(BLowData) & ChrB(BHigData)   '将运算后的数据合成新的字符          Next i     Decrypt = StrDecrypt

End Function

最新回复(0)
      /jishuul2o_2F103J6fFW2eC1kfA6vOE2rTtAUV6AYad1kr1yHw_3D2385460
      8 简首页