gpt4 book ai didi

.net - 如何在WinRT中创建SHA-256哈希?

转载 作者:行者123 更新时间:2023-12-04 05:19:31 27 4
gpt4 key购买 nike

我今天在WinRT中创建了一个简单的单向SHA-256哈希,并意识到它不起作用。我做了一个验证,显然是这样的:

◦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中不允许这样琐碎的事情?

最佳答案

这对您有用吗?

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

关于.net - 如何在WinRT中创建SHA-256哈希?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12503032/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com