![](/img/trans.png)
[英]generate sha256 hash for a string in objective C equivalent to C# without using key
[英]Hash string with SHA256 key
我無法獲得正確的 HASH,我真的不知道它有什么問題。 我得到的所有哈希都不正確,因為在這個網站上: http : //hash.online-convert.com/sha256-generator
public NavigatedPage ()
{
string bytes = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><Command> <LMI_PAYMENT_NO>1000</LMI_PAYMENT_NO><LMI_MERCHANT_ID>2096</LMI_MERCHANT_ID> <LMI_HASH></LMI_HASH> <LMI_PAYMENT_SYSTEM>18</LMI_PAYMENT_SYSTEM> <LMI_PAYMENT_AMOUNT>1001</LMI_PAYMENT_AMOUNT> <LMI_PAYMENT_DESC>Оплата договора</LMI_PAYMENT_DESC></Command>";
string key = "14653285";
string message = bytes;//xml document in a string
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
byte[] keyByte = encoding.GetBytes(key);
HMACSHA256 hmacsha256 = new HMACSHA256(keyByte);
byte[] messageBytes = encoding.GetBytes(message);
byte[] hashmessage = hmacsha256.ComputeHash(messageBytes);
var tempHash = ByteToString(hashmessage);
}
public static string ByteToString(byte[] buff)
{
string sbinary = "";
for ( int i = 0; i < buff.Length; i++ )
{
sbinary += buff[ i ].ToString("X2"); // hex format
}
return ( sbinary );
}
這就是我所做的,但它給了我錯誤的結果。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.