将VBA代码转换为T-SQL代码

时间:2015-08-12 13:45:32

标签: sql-server vba tsql encryption converter

我有一个加密项目,我需要将此VBA代码转换为T-SQL。我是一名SQL开发人员,我很难弄清楚这个VBA代码正在尝试做什么:

Public Function XORDecryption(DataIn As String) As String

Dim lonDataPtr As Long
Dim strDataOut As String
Dim intXOrValue1 As Integer
Dim intXOrValue2 As Integer
Dim CodeKey As String

CodeKey = "R@ndomWord7"

For lonDataPtr = 1 To (Len(DataIn) / 2)
'The first value to be XOr-ed comes from the data to be encrypted
intXOrValue1 = Val("&H" & (Mid$(DataIn, (2 * lonDataPtr) - 1, 2)))
'The second value comes from the code key
intXOrValue2 = Asc(Mid$(CodeKey, ((lonDataPtr Mod Len(CodeKey)) + 1), 1))

strDataOut = strDataOut + Chr(intXOrValue1 Xor intXOrValue2)
Next lonDataPtr
XORDecryption = strDataOut
End Function

此外,此代码也需要转换:

Public Function XOREncryption(DataIn As String) As String

Dim lonDataPtr As Long
Dim strDataOut As String
Dim temp As Integer
Dim tempstring As String
Dim intXOrValue1 As Integer
Dim intXOrValue2 As Integer
Dim CodeKey As String

CodeKey = "R@ndomWord7"
For lonDataPtr = 1 To Len(DataIn)
'The first value to be XOr-ed comes from the data to be encrypted
intXOrValue1 = Asc(Mid$(DataIn, lonDataPtr, 1))
'The second value comes from the code key
intXOrValue2 = Asc(Mid$(CodeKey, ((lonDataPtr Mod Len(CodeKey)) + 1), 1))

temp = (intXOrValue1 Xor intXOrValue2)
tempstring = Hex(temp)
If Len(tempstring) = 1 Then tempstring = "0" & tempstring

strDataOut = strDataOut + tempstring
Next lonDataPtr
XOREncryption = strDataOut
End Function

'USAGE
    Private Sub cmdEncryptdecrypt_Click()
    Dim strEncryptedText As String
    'strCodeKey = InputBox("Please enter your password", "XOr Encryption")
    strEncryptedText = XOREncryption("TestEncryptedWords")
    ' Note:  the strEncryptedText should be:  140B1C1B28390C001D4726250A33001F331C
    MsgBox XORDecryption(strEncryptedText)

End Sub

有人可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

据推测,原作者已经离开,所以...如果你有任何人知道任何版本的VB(.Net,VBS,VBA,VB Classic),请在逆向工程VBA代码中获得帮助。

一旦了解了VBA代码的内容和方式,您就能够匹配TSQL中的功能。

否则......这是火灾的试验。对VB命令进行Web搜索并逐一学习。幸运的是,在那块逻辑中没有太多。