2012-09-19 32 views
7

Fui a crear un hash SHA-256 de un solo sentido en WinRT hoy y me di cuenta de que no funcionaba. Hice una validación y al parecer tengo esto:Cómo crear hashes SHA-256 en WinRT?

◦API System.Security.Cryptography.SHA256Managed en mscorlib, publicKeyToken = b77a5c561934e089 no es compatible con esta aplicación tipo. CryptoWinRT.exe llama a esta API. ◦API System.Security.Cryptography.HashAlgorithm en MSCORLIB, PUBLICKEYTOKEN = B77A5C561934E089 no es compatible con esta aplicación tipo . CryptoWinRT.exe llama a esta API. ◦API System.Security.Cryptography.SHA256Administración. # Ctor en MSCORLIB, PUBLICKEYTOKEN = B77A5C561934E089 no es compatible con esta aplicación tipo . CryptoWinRT.exe llama a esta API. ◦API System.Security.Cryptography.HashAlgorithm.ComputeHash (System.Byte []) en MSCORLIB, PUBLICKEYTOKEN = B77A5C561934E089 no es compatible con este tipo de aplicación . CryptoWinRT.exe llama a esta API.

¿Cuál es el reemplazo de esto? ¿Y por qué no se permitiría algo tan trivial en WinRT?

+0

duplicados de [¿Cómo realizo un hash SHA512 en C++ WinRT?] (Http://stackoverflow.com/questions/12355417/how-do-i-perform-a-sha512-hash-in- c-winrt) (Algoritmo hash diferente, pero la respuesta es la misma.) –

Respuesta

17

¿Esto funciona para usted?

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

En realidad terminé haciendo casi exactamente esto. Simplemente nunca volví a aquí y publiqué una respuesta – Earlz