-
Notifications
You must be signed in to change notification settings - Fork 1
MirzaCryptoHelpers.Hashings
Mirza Ghulam Rasyid edited this page Oct 6, 2017
·
3 revisions
This namespace contains wrappers for hash algorithms that have same signatures. All core classes implement IHashCrypto interface so that it can be used for dependency injection together with general class HashCrypto that its constructor accepts any implementation of IHashCrypto interface. By default, HashCrypto class uses SHA256Crypto class if no parameter being passed. One thing to note, if there's some failure during hashing, null/empty value will be returned.
Samples in this wiki will use SHA256Crypto class as all core classes have same signatures.
Add namespaces first.
using MirzaCryptoHelpers.Hashings;
using MirzaCryptoHelpers.Common; //for BitHelpers class
string message = "This is a statement.";
byte[] hashedMessage = new SHA256Crypto().GetHashBytes(message);
//result: byte[32] { 59, 166, 141, 240, 166, 229, 211, 75, 37, 247, 78, 154, .......... }
byte[] messageInBytes = BitHelpers.ConvertStringToBytes(message); //message variable is from previous sample
byte[] hashedMessage2 = new SHA256Crypto().GetHashBytes(messageInBytes);
//result: same as previous sample.
string message = "This is a statement."; //in string format
byte[] messageInBytes = BitHelpers.ConvertStringToBytes(message); //in bytes format
string hashedMessage1 = new SHA256Crypto().GetHashBase64String(message);
string hashedMessage2 = new SHA256Crypto().GetHashBase64String(messageInBytes);
//result: both will return O6aN8Kbl00sl906ahupKmwbiW0niioY4hcxUzZy55xo=