我有一段时间试图用md5对PHP进行哈希处理......我尝试移植到PHP的VB代码使用了ComputeHash,它接受一个字节[]并执行整个数组的散列。如何在PHP中模拟computeHash vb函数
Public Shared Function HashBytesMD5(ByVal strInput As String) As Guid
Dim oHasher As Cryptography.MD5 = Cryptography.MD5.Create()
Dim oEncoder As New System.Text.UTF8Encoding()
Dim csData() As Byte
csData = oEncoder.GetBytes(strInput)
csData = oHasher.ComputeHash(oEncoder.GetBytes(strInput))
Return New Guid(csData)
End Function
现在,我有以下创建一个ascii值的数组。现在我需要md5它像VB.Net一样。它似乎并不像看起来那么直截了当。
$passHash = $this->ConvertToASCII('123456');
$passHash = md5(serialize($passHash));
/*
* Converts a string to ascii (byte) array
*/
function ConvertToASCII($password)
{
$byteArray = array();
for ($i=0; $i < strlen($password); $i++) {
array_push($byteArray,ord(substr($password,$i)));
}
return $byteArray;
}
注意:在第一个值是字符computeHash MD5之前123456
字节数组
**index** **Value**
[0] 49
[1] 50
[2] 51
[3] 52
[4] 53
[5] 54
字节数组从VB computeHash函数返回的ACII值 指数值
[0] 225
[1] 10
[2] 220
[3] 57
[4] 73
[5] 186
[6] 89
[7] 171
[8] 190
[9] 86
[10] 224
[11] 87
[12] 242
[13] 15
[14] 136
[15] 62
在第一次看我不确定这个w应该通过md5'串行化的字节数组来完成。 Sidenote:你使用'substr()'的方式是从'$ i'开始的所有字符串,而我想你只是想要这个单一字符:'substr($ password,$ i,1)' – Fanis 2011-04-04 22:26:33
我得到了php功能来自php手册中的评论。我做了一个print_r,它似乎工作。 – chobo 2011-04-04 22:33:01
nvm你是对的:)好的赶上。 – chobo 2011-04-04 22:47:05