Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

How to use Sha/hash in Xamarin

I want to hash a String with C# in Xamarin. Normally i 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++)
    {
        sBuilder.Append(data[i].ToString("x2"));
    }
    // Return the hexadecimal string.
    input = sBuilder.ToString();
    return (input);
}

But in Xamarin i seem not able to include this library. Now i was wondering, if there is a way to include this library or an alternitive to easily hash a Password.

Best Answer

Answers

  • vkmivkmi ITMember

    Sorry to bump this thread after so long, but I find myself having some problems implementing a method to hash sensible data.
    I'm trying @MichaelRumpler method, but as I don't have System.Security.Cryptography available, so I don't have Windows.Security.Cryptography available in my PCL.

    Or am I getting the answer wrong and the suggestion is to implement platform specific code to hash strings and call it through an interface?

  • NMackayNMackay GBInsider, University admin

    @vkmi

    Use the dependency service and do the encryption in the platform specific project.

Sign In or Register to comment.