【问题标题】:Convert C# HMAC SHA256 to work on Windows 8.1 universal app将 C# HMAC SHA256 转换为在 Windows 8.1 通用应用程序上工作
【发布时间】:2015-02-13 07:16:56
【问题描述】:

正在尝试将此代码转换为适用于通用应用程序...

namespace Test
{
  public class MyHmac
  {
    private string CreateToken(string message, string secret)
    {
      secret = secret ?? "";
      var encoding = new System.Text.ASCIIEncoding();
      byte[] keyByte = encoding.GetBytes(secret);
      byte[] messageBytes = encoding.GetBytes(message);
      using (var hmacsha256 = new HMACSHA256(keyByte))
      {
        byte[] hashmessage = hmacsha256.ComputeHash(messageBytes);
        return Convert.ToBase64String(hashmessage);
      }
    }
  }
}

...由于System.Security.Cryptography 不可用,我无法找到 HMACSHA256(或类似类)在新框架中的位置。

【问题讨论】:

标签: c# windows-phone-8.1 windows-8.1


【解决方案1】:

Windows 应用商店应用的加密命名空间是 Windows.Security.Cryptography 和 Windows.Security.Cryptography.Core

新的 Hash Algorithm Provider 支持多种算法(包括 SHA256)

这里有一些很好的例子https://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.security.cryptography.core.hashalgorithmprovider

-阿乔德

【讨论】:

    猜你喜欢
    • 2016-07-02
    • 1970-01-01
    • 2015-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多