How to create SHA-256 hashes in WinRT?(如何在 WinRT 中创建 SHA-256 哈希?)
问题描述
我今天在 WinRT 中创建了一个简单的单向 SHA-256 哈希,发现它不起作用.我做了一个验证,显然得到了这个:
I went to create a simple one-way SHA-256 hash in WinRT today and realized it didn't work. I did a validation and apparently got this:
◦API System.Security.Cryptography.SHA256在 MSCORLIB 中管理,此应用程序不支持 PUBLICKEYTOKEN=B77A5C561934E089类型.CryptoWinRT.exe 调用此 API.◦APIMSCORLIB 中的 System.Security.Cryptography.HashAlgorithm,此应用程序不支持 PUBLICKEYTOKEN=B77A5C561934E089类型.CryptoWinRT.exe 调用此 API.◦APIMSCORLIB 中的 System.Security.Cryptography.SHA256Managed.#ctor,此应用程序不支持 PUBLICKEYTOKEN=B77A5C561934E089类型.CryptoWinRT.exe 调用此 API.◦APISystem.Security.Cryptography.HashAlgorithm.ComputeHash(System.Byte[])在 MSCORLIB 中,不支持 PUBLICKEYTOKEN=B77A5C561934E089申请类型.CryptoWinRT.exe 调用此 API.
◦API System.Security.Cryptography.SHA256Managed in MSCORLIB, PUBLICKEYTOKEN=B77A5C561934E089 is not supported for this application type. CryptoWinRT.exe calls this API. ◦API System.Security.Cryptography.HashAlgorithm in MSCORLIB, PUBLICKEYTOKEN=B77A5C561934E089 is not supported for this application type. CryptoWinRT.exe calls this API. ◦API System.Security.Cryptography.SHA256Managed.#ctor in MSCORLIB, PUBLICKEYTOKEN=B77A5C561934E089 is not supported for this application type. CryptoWinRT.exe calls this API. ◦API System.Security.Cryptography.HashAlgorithm.ComputeHash(System.Byte[]) in MSCORLIB, PUBLICKEYTOKEN=B77A5C561934E089 is not supported for this application type. CryptoWinRT.exe calls this API.
这个的替代品是什么?为什么WinRT不允许这种微不足道的事情呢?
What is the replacement for this? And why would such a trivial thing not be allowed in WinRT?
推荐答案
这对你有用吗?
private void HandleHashClick(object sender, RoutedEventArgs e)
{
// get the text...
var inputText = this.textInput.Text;
// put the string in a buffer, UTF-8 encoded...
IBuffer input = CryptographicBuffer.ConvertStringToBinary(inputText,
BinaryStringEncoding.Utf8);
// hash it...
var hasher = HashAlgorithmProvider.OpenAlgorithm("SHA256");
IBuffer hashed = hasher.HashData(input);
// format it...
this.textBase64.Text = CryptographicBuffer.EncodeToBase64String(hashed);
this.textHex.Text = CryptographicBuffer.EncodeToHexString(hashed);
}
这篇关于如何在 WinRT 中创建 SHA-256 哈希?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 WinRT 中创建 SHA-256 哈希?
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- 输入按键事件处理程序 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01