This repository has been archived by the owner on Jan 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Home
Henkje edited this page Apr 11, 2019
·
11 revisions
First download the nuget package and add the namespace "SimpleHashing".
Example of generating a hash with the input "12345":
string hash = PBKDF2.Hash("12345");
Example of verifying a generated hash:
string hash = PBKDF2.Hash("12345");
bool equals = PBKDF2.Verify(hash, "12345");//true
bool equals2 = PBKDF2.Verify(hash, "54321");//false
Specify the Iterations of PBKDF2(Default = 50000). Iterations need to be the same when using Verify and Hash, else the output will be different and Verify will return false.
string hash = PBKDF2.Hash("12345", 30000);
bool equals = PBKDF2.Verify(hash, "12345", 30000);
//Iterations need to be the same, or Verify will return false.
Specify the length of the hash(Default = 32). This will not be the length of the output. The length of the output will be: 16 + length of hash. Those 16 bytes are used to store the random generated salt.
string hash = PBKDF2.Hash(Input, Length: 60);
string hash2 = PBKDF2.Hash(Input, 3000, 60);//With Iterations
bool equals = PBKDF2.Verify(hash, Input);//Verify will automaticly detect the length
Works the same as hashing a string, but now the input and output is a byte[].
byte[] input = Encoding.UTF8.GetBytes("12345");
byte[] hash = PBKDF2.Hash(input);
bool equals = PBKDF2.Verify(hash, input);
Overloads of the Hash function:
static string Hash(string input, int iterations = 50000, int length = 32)
static byte[] Hash(byte[] input, int iterations = 50000, int length = 32)
Overloads of the Verify function:
static bool Verify(string hashedInput, string input, int iterations = 50000)
static bool Verify(byte[] hashedInput, byte[] input, int iterations = 50000)