Dot-Net
如何在 WinRT 中創建 SHA-256 雜湊?
我今天在 WinRT 中創建了一個簡單的單向 SHA-256 雜湊,並意識到它不起作用。我做了一個驗證,顯然得到了這個:
◦API System.Security.Cryptography.SHA256Managed in MSCORLIB, PUBLICKEYTOKEN=B77A5C561934E089 不支持此應用程序類型。CryptoWinRT.exe 呼叫此 API。◦此應用程序類型不支持 MSCORLIB 中的 API System.Security.Cryptography.HashAlgorithm,PUBLICKEYTOKEN=B77A5C561934E089。CryptoWinRT.exe 呼叫此 API。◦API System.Security.Cryptography.SHA256Managed.#ctor in MSCORLIB, PUBLICKEYTOKEN=B77A5C561934E089 不支持此應用程序類型。CryptoWinRT.exe 呼叫此 API。◦API System.Security.Cryptography.HashAlgorithm.ComputeHash(System.Byte
$$ $$) 在 MSCORLIB 中,此應用程序類型不支持 PUBLICKEYTOKEN=B77A5C561934E089。CryptoWinRT.exe 呼叫此 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); }