encryption - 这套VB6加密函数能破解吗?

标签 encryption vb6 cryptography

 Public Function EncryptString(theString As String, TheKey As String) As String
    Dim X As Long
    Dim eKey As Byte, eChr As Byte, oChr As Byte, tmp$
    For i = 1 To Len(TheKey)
         'generate a key
          eKey = Asc(Mid$(TheKey, i, 1)) Xor eKey
    Next

    'reset random function
    Rnd -1
    'initilize our key as the random seed
    Randomize eKey
    'generate a pseudo old char
    oChr = Int(Rnd * 256)
    'start encryption
    For X = 1 To Len(theString)
        pp = pp + 1
        If pp > Len(TheKey) Then pp = 1
        eChr = Asc(Mid$(theString, X, 1)) Xor _
                   Int(Rnd * 256) Xor Asc(Mid$(TheKey, pp, 1)) Xor oChr
        tmp$ = tmp$ & Chr(eChr)
        oChr = eChr
    Next
    EncryptString = AsctoHex(tmp$)    

End Function


Public Function DecryptString(theString As String, TheKey As String) As String

Dim X As Long
Dim eKey As Byte, eChr As Byte, oChr As Byte, tmp$
For i = 1 To Len(TheKey)
     'generate a key
     eKey = Asc(Mid$(TheKey, i, 1)) Xor eKey
Next
'reset random function
Rnd -1
'initilize our key as the random seed
Randomize eKey
'generate a pseudo old char
oChr = Int(Rnd * 256)
'start decryption
tmp$ = HexToAsc(theString)
    DecryptString = ""
    For X = 1 To Len(tmp$)
    pp = pp + 1
    If pp > Len(TheKey) Then pp = 1
    If X > 1 Then oChr = Asc(Mid$(tmp$, X - 1, 1))
    eChr = Asc(Mid$(tmp$, X, 1)) Xor Int(Rnd * 256) Xor _
           Asc(Mid$(TheKey, pp, 1)) Xor oChr
        DecryptString = DecryptString & Chr$(eChr)
Next

End Function


Private Function AsctoHex(ByVal astr As String)

For X = 1 To Len(astr)
hc = Hex$(Asc(Mid$(astr, X, 1)))
nstr = nstr & String(2 - Len(hc), "0") & hc
Next
AsctoHex = nstr

End Function

最佳答案

你永远不应该尝试自己实现这样的加密。很难正确地做,而且很容易意外地建立漏洞。

找到一个已经证明有效并经过大量测试的现有解决方案会更容易、更安全。 This可能是更好的解决方案。

关于encryption - 这套VB6加密函数能破解吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10730548/

相关文章:

c - 加密解密错误(一次性一密加密)

arrays - VBA数组排序功能?

vb6 - 遗留 Visual Basic 代码中的隐式 ByRef

vb6 - 免费的 VB 6.0 反编译器?

c# - AES 256 的盐大小和位置是多少?

javascript - 为什么 Node crypto 会为同一个字符串返回不同的值?

encryption - 最好的加密机制是Triple DES或RC4?

web-services - 在没有 HTTPS 或私有(private)共享 key 的情况下保护 "open"Web 服务

android - 如何在 android 中创建一个 .Gzip 文件并加密和解密该文件?

java - 升级到 1.45 时出现 BouncyCaSTLe AES 错误