I need to convert a String to a MD5 or SHA1 hash, can you help me?
SHA1 sh1 = SHA1.Create();
String hash = "this is my plaintext";
System.Text.ASCIIEncoding encoding=new System.Text.ASCIIEncoding();
byte bytes = encoding.GetBytes(hash);
byte result = sh1.ComputeHash(bytes);
Probably don't use ASCII, the encoding changes from region to region. Use UTF8 instead, otherwise sometimes depending on region you may produce a different digest for the same input (and so fail validation).
where do i find SHA1 class? "System.Security.Cryptography" dont have "SHA1"
It's listed in the docs for Android, iOS, and Mac:
Maybe you haven't included System.Core in references?
I could not add to PCL, I had to use the same solution for Android and iPhone
I just did this in PCL for an android app I was prototyping.
I found two PCL libraries that supported MD5, one supported SHA1.
Both were really easy to use..https://pclcontrib.codeplex.com/https://hmacmd5.codeplex.com/
Hope that helps!
@WilliamRoper Were you able to use PCL Contrib in Xamarin? I can't install it because package from NuGet doesn't support iOS and Android platforms.
I used the second link, the http://hmacmd5.codeplex.com project.
I was able to install it in a pcl and call it from android with no problems.
Hope that helps.
Xamarin Inc., as a wholly-owned Microsoft subsidiary acting as a separate legal entity, adheres to the Microsoft Privacy Statement: Privacy & cookies