Windows Phone 8.1上的HMACSHA256? [英] HMACSHA256 on Windows Phone 8.1?

查看:222
本文介绍了Windows Phone 8.1上的HMACSHA256?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据这篇MSDN文章,存在一个类,用于在WP8上的System.Security.Cryptography命名空间中生成HMACSHA256哈希代码。但是.Cryptography命名空间似乎不存在。是我的项目有问题,还是这个文档错了?有没有另一种方法来计算WP8上的HMACSHA256哈希值?

According to this MSDN article, there exists a class for generating HMACSHA256 hash codes in the System.Security.Cryptography namespace on WP8. However, the .Cryptography namespace doesn't appear to exist. Is something wrong with my project or is this documentation wrong? Is there another way to compute HMACSHA256 hashes on WP8?

http://msdn.microsoft.com/library/windows/apps/system.security.cryptography.hmacsha256(v = vs.105) .aspx

推荐答案

经过多少痛苦,我有一个能工作的函数。

After much anguish, I have a function that works.

public static string HmacSha256(string secretKey, string value)
{
    // Move strings to buffers.
    var key = CryptographicBuffer.ConvertStringToBinary(secretKey, BinaryStringEncoding.Utf8);
    var msg = CryptographicBuffer.ConvertStringToBinary(value, BinaryStringEncoding.Utf8);

    // Create HMAC.
    var objMacProv = MacAlgorithmProvider.OpenAlgorithm(MacAlgorithmNames.HmacSha256);
    var hash = objMacProv.CreateHash(key);
    hash.Append(msg);
    return CryptographicBuffer.EncodeToHexString(hash.GetValueAndReset());
}

这篇关于Windows Phone 8.1上的HMACSHA256?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆