小编JP *_*ans的帖子

在Windows应用商店中使用hmacsha256

我正在将Windows Phone 7.1应用程序迁移/转换/重建为Windows 8商店应用程序.

我在de WP7应用程序中使用的一种方法是给我带来麻烦:

private byte[] GetSHA256Key(string data, string secretKey)
{
    byte[] value = Encoding.UTF8.GetBytes(data);
    byte[] secretKeyBytes = Encoding.UTF8.GetBytes(secretKey);

    HMACSHA256 hmacsha256 = new HMACSHA256(secretKeyBytes);

    byte[] resultBytes = hmacsha256.ComputeHash(value);

    return resultBytes;
}
Run Code Online (Sandbox Code Playgroud)

查看Windows应用商店应用的文档,我想出了这个新代码,我希望能给出相同的结果.但不是.我做错了什么.但是什么?

private byte[] GetSHA256Key(string value, string secretKey)
{
        // Create a MacAlgorithmProvider object for the specified algorithm.
        MacAlgorithmProvider objMacProv = MacAlgorithmProvider.OpenAlgorithm(MacAlgorithmNames.HmacSha256);

        // Create a buffer that contains the message to be signed.
        IBuffer valueBuffer = CryptographicBuffer.ConvertStringToBinary(value, BinaryStringEncoding.Utf8);

        // Create a key to be signed with the message. …
Run Code Online (Sandbox Code Playgroud)

c# cryptography windows-phone-7 microsoft-metro

8
推荐指数
2
解决办法
1881
查看次数