如何解决用PHP加密和用VBA解密
我用PHP加密敏感数据并在Excel中处理数据。
function xor_string($string,$key) {
for($i = 0; $i < strlen($string); $i++)
$string[$i] = dechex(ord(($string[$i] ^ $key[$i % strlen($key)])));
return $string;
}
以下代码用于解密VBA中的字符串:
Public Function XORDecryption(CodeKey As String,DataIn As String) As String
Dim arkdata1 As Long
Dim strDataOut As String
Dim intXOrValue1 As Integer
Dim intXOrValue2 As Integer
For arkdata1 = 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 * arkdata1) - 1,2)))
'The second value comes from the code key
intXOrValue2 = Asc(Mid$(CodeKey,((arkdata1 Mod Len(CodeKey)) + 1),1))
strDataOut = strDataOut + Chr(intXOrValue1 Xor intXOrValue2)
Next arkdata1
XORDecryption = strDataOut
End Function
加密过程: 使用字符串“ 123456897”和键“ 2405”,PHP函数返回“ 011151314f0”
解密过程: VBA函数使用字符串“ 011151314f0”和键“ 2405”返回“ 5!d {0”
我找不到VBA函数不返回“ 123456897”的原因:(
谢谢!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。