2012-09-19 14 views
7

Oggi sono andato a creare un semplice hash SHA-256 unidirezionale in WinRT e ho capito che non funzionava. Ho fatto una convalida e apparentemente ottenuto questo:Come creare gli hash SHA-256 in WinRT?

◦API System.Security.Cryptography.SHA256Managed in mscorlib, PublicKeyToken = b77a5c561934e089 non è supportata per questa applicazione tipo. CryptoWinRT.exe chiama questa API. ◦API System.Security.Cryptography.HashAlgorithm in MSCORLIB, PUBLICKEYTOKEN = B77A5C561934E089 non supportato per questa applicazione tipo. CryptoWinRT.exe chiama questa API. ◦API System.Security.Cryptography.SHA256Managed. # Ctor in MSCORLIB, PUBLICKEYTOKEN = B77A5C561934E089 non supportato per questa applicazione tipo. CryptoWinRT.exe chiama questa API. ◦API System.Security.Cryptography.HashAlgorithm.ComputeHash (System.Byte []) in MSCORLIB, PUBLICKEYTOKEN = B77A5C561934E089 non è supportato per questo tipo di applicazione . CryptoWinRT.exe chiama questa API.

Qual è il sostituto di questo? E perché una cosa così banale non dovrebbe essere consentita in WinRT?

+0

duplicato di [Come si esegue un hash SHA512 in C++ WinRT?] (Http://stackoverflow.com/questions/12355417/how-do-i-perform-a-sha512-hash-in- c-winrt) (Algoritmo di hash diverso, ma la risposta è la stessa.) –

risposta

17

Funziona per voi?

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

In realtà ho finito per fare quasi esattamente questo. Non sono mai tornato qui e ho postato una risposta – Earlz