Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculate SHA256 hash WITHOUT System.Security.Cryptography

I’m moving one of my libraries to Xamarin PLC.

The official documentation states that System.Security.Cryptography namespace is supported, but it is not in actual code.

I’m looking for a way to compute SHA256 hash without this namespace (And without HashAlgorithmProvider in Windows namespace. This method breaks application for Android and WP8.0)

like image 607
Jurion Avatar asked Oct 20 '25 08:10

Jurion


1 Answers

Test something like this using Bouncy Castle PCL lib (https://www.nuget.org/packages/Portable.BouncyCastle/)

var encData = Encoding.UTF8.GetBytes("TESTHASH");
Org.BouncyCastle.Crypto.Digests.Sha256Digest myHash = new Org.BouncyCastle.Crypto.Digests.Sha256Digest();
myHash.BlockUpdate (encData, 0, encData.Length);
byte[] compArr = new byte[myHash.GetDigestSize ()];
myHash.DoFinal (compArr, 0);
like image 104
Alejandro Ruiz Varela Avatar answered Oct 21 '25 22:10

Alejandro Ruiz Varela