如何创建SHA-256散列在WinRT的? [英] How to create SHA-256 hashes in WinRT?

查看:191
本文介绍了如何创建SHA-256散列在WinRT的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我到今天的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:

◦APISystem.Security.Cryptography.SHA256Managed在MSCORLIB,   公钥= B77A5C561934E089不支持此应用程序   类型。 CryptoWinRT.exe调用此API。 ◦API   System.Security.Cryptography.HashAlgorithm在MSCORLIB,   公钥= B77A5C561934E089不支持此应用程序   类型。 CryptoWinRT.exe调用此API。 ◦API   System.Security.Cryptography.SHA256Managed#构造函数中MSCORLIB,   公钥= B77A5C561934E089不支持此应用程序   类型。 CryptoWinRT.exe调用此API。 ◦API   System.Security.Cryptography.HashAlgorithm.ComputeHash(System.Byte [])   在MSCORLIB公钥= 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);
    }

这篇关于如何创建SHA-256散列在WinRT的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆