Olias Olias - 1 year ago 113
C# Question

How to use Hash SHA in Xamarin

I want to hash a String with C# in Xamarin.
Normally I'd use:

using System.Security.Cryptography;

public string SHA512StringHash(String input)
SHA512 shaM = new SHA512Managed();
// Convert the input string to a byte array and compute the hash.
byte[] data = shaM.ComputeHash(Encoding.UTF8.GetBytes(input));
// Create a new Stringbuilder to collect the bytes
// and create a string.
StringBuilder sBuilder = new StringBuilder();
// Loop through each byte of the hashed data
// and format each one as a hexadecimal string.
for (int i = 0; i < data.Length; i++)
// Return the hexadecimal string.
input = sBuilder.ToString();
return (input);

But in Xamarin I don't seem able to include this library.
Is there a way to include this library or an alternative to easily hash a Password?

Answer Source

I found the solution, i was trying to create this class in the Forms Solution, but in this Solution using System.Security.Cryptography; is not available. In the iOS and Android Solution it is available. So i implemented an Interface in the Forms Solution and used the Method in the iOS and Android Solution.