问题描述
我正在尝试使用PHP对md5进行hash转换...我正在尝试使用PHP的VB代码使用ComputeHash,它使用一个byte []并在整个数组上执行散列。 / p> 公共共享函数HashBytesMD5(ByVal strInput As String)作为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))
返回新的Guid(csData)
结束函数
现在我已经创建了一个数组ascii值。现在我需要md5它像VB.Net。它似乎并不像看起来那么简单。
$ passHash = $ this-> ConvertToASCII('123456 );
$ passHash = md5(serialize($ passHash));
/ *
*将字符串转换为ascii(byte)数组
* /
函数ConvertToASCII($ password)
{
$ byteArray = array(); ($ i = 0; $ i< strlen($ password); $ i ++){
array_push($ byteArray,ord(substr($ password,$ i)))
;
}
return $ byteArray;
}
注意:第一个值是字符数123456
computeHash之前的字节数组md5
**索引** **价值**
[0] 49
[1] 50
[2] 51
[3] 52
[4] 53
[5] 54
从VB computeHash函数返回的字节数组
索引 strong>值
[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
我的VB.NET非常生锈,但似乎像 MD5.ComputeHash()
的输出可以通过运行您的输入通过 md5()
,然后取每对十六进制字符(字节)并转换成十进制。
$ passHash = md5('123456');
$ strlen = strlen($ passHash);
$ hashedBytes = array();
$ i = 0;
while($ i< $ strlen){
$ pair = substr($ passHash,$ i,2);
$ hashedBytes [] = hexdec($ pair);
$ i = $ i + 2;
}
I am having a hell of a time trying to md5 hash this with PHP... The VB code I am trying to port to PHP uses ComputeHash which takes in a byte[] and performs a hash on the whole array.
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
Right now I have the following which creates an array of ascii values. Now I need to md5 it like VB.Net does. It doesn't seem to be as straightforward as it may seem.
$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;
}
Note: the values in the first are the acii values for the characters 123456
Byte array before computeHash md5
**index** **Value**
[0] 49
[1] 50
[2] 51
[3] 52
[4] 53
[5] 54
Byte array returned from VB computeHash functionindex value
[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
My VB.NET is very rusty but it seems like MD5.ComputeHash()
's output could be recreated by running your input through md5()
and then taking each pair of hex characters (byte) and converting into decimal.
$passHash = md5('123456');
$strlen = strlen($passHash) ;
$hashedBytes = array() ;
$i = 0 ;
while ($i < $strlen) {
$pair = substr($passHash, $i, 2) ;
$hashedBytes[] = hexdec($pair) ;
$i = $i + 2 ;
}
这篇关于如何在PHP中模仿computeHash vb函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!