将C#HMAC SHA256转换为在Windows 8.1通用应用程序上工作

将C#HMAC SHA256转换为在Windows 8.1通用应用程序上工作,c#,windows-phone-8.1,windows-8.1,C#,Windows Phone 8.1,Windows 8.1,正在尝试将此代码转换为通用应用程序 namespace Test { public class MyHmac { private string CreateToken(string message, string secret) { secret = secret ?? ""; var encoding = new System.Text.ASCIIEncoding(); byte[] keyByte = encoding.GetByt

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

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);
      }
    }
  }
}

。。。我很难找到HMACSHA256(或类似的类)在新框架中的位置,因为
System.Security.Cryptography
不可用。

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

新的哈希算法提供程序支持多种算法(包括SHA256)

这里有一些很好的例子

-Achod

可能重复的