简体   繁体   English

Vb.Net 256哈希到PHP 256哈希

[英]Vb.Net 256 Hash to PHP 256 Hash

I have VB.Net method that does this: 我有这样做的VB.Net方法:

' Step 1: UTF8 Encodes
Dim uEncode As New UnicodeEncoding()

' Step 2: Creates Byte Array from UTF8 encoded string
Dim bytClearString() As Byte = uEncode.GetBytes(ClearString)

' Step 3: Creates the hash from the byte array
Dim sha As New System.Security.Cryptography.SHA256Managed()
Dim hash() As Byte = sha.ComputeHash(bytClearString)

' Base64 Encodes the hash
Return Convert.ToBase64String(hash)

In PHP I'm doing this: 在PHP中,我正在这样做:

// Step 1 utf8 encode
$tohash = utf8_encode('testinfostring');

// Step 2 cast string to byte array
Not sure about this step...

// Step 3
$hash = hash('sha256', $tohash, true);

// Step 4 convert hashed array to base64 encoded string
echo base64_encode($hash);

The output from my VB.Net method differs from the PHP and I think it's that VB encryption is happening on the byte array while PHP is on the string itself. 我的VB.Net方法的输出与PHP不同,我认为VB加密发生在字节数组上,而PHP在字符串本身上。

Any help is greatly appreciated! 任何帮助是极大的赞赏!

The solution was to change the PHP from: 解决方案是将PHP从以下位置更改:

$tohash = utf8_encode('testinfostring');

to: 至:

$tohash = mb_convert_encoding('testinfostring', 'UTF-16LE', 'UTF-8');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM