[英]Vb.Net 256 Hash to PHP 256 Hash
我有這樣做的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)
在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);
我的VB.Net方法的輸出與PHP不同,我認為VB加密發生在字節數組上,而PHP在字符串本身上。
任何幫助是極大的贊賞!
解決方案是將PHP從以下位置更改:
$tohash = utf8_encode('testinfostring');
至:
$tohash = mb_convert_encoding('testinfostring', 'UTF-16LE', 'UTF-8');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.