对于给定的字符串key
和给定的字符串,baseString
您可以按如下方式加密基本字符串:
byte[] keyBytes = System.Text.Encoding.UTF8.GetBytes(key);
System.Security.Cryptography.HMACSHA256 sha1 = new System.Security.Cryptography.HMACSHA256(keyBytes);
byte[] hashBytes = sha1.ComputeHash(System.Text.Encoding.UTF8.GetBytes(baseString));
string hash = Convert.ToBase64String(hashBytes);
Run Code Online (Sandbox Code Playgroud)
注意:这只是标准的.Net代码,并非特定于Windows Phone 7.
注意2:但是这在Windows 8商店应用程序中不起作用,但这是另一个商店.