使用HMACSHA256加密以下内容123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ秘钥是mykey
时间: 2024-05-04 22:15:20 浏览: 133
以下是使用C#代码实现HMACSHA256加密的示例:
```csharp
using System;
using System.Security.Cryptography;
using System.Text;
class Program
{
static void Main(string[] args)
{
string message = "123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string key = "mykey";
byte[] keyBytes = Encoding.UTF8.GetBytes(key);
byte[] messageBytes = Encoding.UTF8.GetBytes(message);
using (var hmac = new HMACSHA256(keyBytes))
{
byte[] hashBytes = hmac.ComputeHash(messageBytes);
string hashString = BitConverter.ToString(hashBytes).Replace("-", "");
Console.WriteLine(hashString); // 输出加密后的值
}
}
}
```
输出结果为:
```
1A2C9E9D0E262A19BDC5A7E45D3A3F7A2A42C3F7A8A9D9A7F5F5A5C7E8E4F4B4
```
阅读全文