Ros*_*oss 3 amazon-web-services asp.net-core
我需要将以下.Net代码转换为.Net Core:
static byte[] HmacSHA256(String data, byte[] key)
{
String algorithm = "HmacSHA256";
KeyedHashAlgorithm kha = KeyedHashAlgorithm.Create(algorithm);
kha.Key = key;
return kha.ComputeHash(Encoding.UTF8.GetBytes(data));
}
Run Code Online (Sandbox Code Playgroud)
以上代码段用于Amazon AWS密钥签名,并从此处获取.
我正在使用System.Security.Cryptography.Primitives 4.3.0和KeyedHashAlgorithm.Create方法不存在.看看github,我可以看到Create方法现在存在,但它不受支持:
public static new KeyedHashAlgorithm Create(string algName)
{
throw new PlatformNotSupportedException();
}
Run Code Online (Sandbox Code Playgroud)
问题是.Net Core中我对KeyedHashAlgorithm.Create(string algName)的替代方法是什么?
.Net Core似乎提供HMACSHA256 Class,它应该是您所需要的:
static byte[] HmacSHA256(String data, byte[] key)
{
HMACSHA256 hashAlgorithm = new HMACSHA256(key);
return hashAlgorithm.ComputeHash(Encoding.UTF8.GetBytes(data));
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1061 次 |
最近记录: |