Advanced _Scrypt - Chewhern/ASodium GitHub Wiki

For detailed documentation, kindly refer to official libsodium.

It's extremely important that you follow the guidelines from libsodium to avoid having any sorts of security vulnerabilities and like what libsodium has stated.., don't use Scrypt unless you have a reason to use it.

Deriving keys from password

Default Key Deriviation

Initial Functions

public static Byte[] PBKDF2(long DerivedKeyLength,Byte[] Password,Byte[] Salt,STRENGTH strength = STRENGTH.INTERACTIVE,Boolean ClearKey=false) 

Example Code

Byte[] RandomPassword = SodiumRNG.GetRandomBytes(128);
Byte[] Salt = SodiumPasswordHashScryptSalsa208SHA256.GenerateSalt();
Byte[] DerivedKey = SodiumPasswordHashScryptSalsa208SHA256.PBKDF2(32, RandomPassword, Salt);

Custom Key Derivation

Initial Functions

public static Byte[] CustomPBKDF2(long DerivedKeyLength, Byte[] Password, Byte[] Salt, long OpsLimit,long MemLimit,Boolean ClearKey=false)

Example Code

Byte[] RandomPassword = SodiumRNG.GetRandomBytes(128);
Byte[] Salt = SodiumPasswordHashScryptSalsa208SHA256.GenerateSalt();
Byte[] DerivedKey = SodiumPasswordHashScryptSalsa208SHA256.CustomPBKDF2(32, RandomPassword, Salt, 1048576 ,33554432);

Password processing and storing

Initial Functions

public static Boolean VerifyPassword(String ComputedPasswordHashWithParams,Byte[] Password,Boolean ClearKey=false)
public static int HashedPasswordWithParamsNeedReHash(String ComputedPasswordHashWithParams,STRENGTH strength =  STRENGTH.INTERACTIVE)

Example Code

Byte[] RandomPassword = SodiumRNG.GetRandomBytes(128);
String HashedPasswordWithParams = SodiumPasswordHashScryptSalsa208SHA256.ComputePasswordHash(RandomPassword);
int NeedsRehash = SodiumPasswordHashScryptSalsa208SHA256.HashedPasswordWithParamsNeedReHash(HashedPasswordWithParams);
MessageBox.Show(NeedsRehash.ToString());

Default password processing and storing

Initial Functions

public static String ComputePasswordHash(Byte[] Password, STRENGTH strength = STRENGTH.INTERACTIVE,Boolean ClearKey=false)

Example Code

Byte[] RandomPassword = SodiumRNG.GetRandomBytes(128);
String HashedPasswordWithParams = SodiumPasswordHashScryptSalsa208SHA256.ComputePasswordHash(RandomPassword);
Boolean VerifyPassword = SodiumPasswordHashScryptSalsa208SHA256.VerifyPassword(HashedPasswordWithParams,RandomPassword);

Custom password processing and storing

Initial Functions

public static String CustomComputePasswordHash(Byte[] Password, long OpsLimit, long MemLimit,Boolean ClearKey=false)

Example Code

Byte[] RandomPassword = SodiumRNG.GetRandomBytes(128);
String HashedPasswordWithParams = SodiumPasswordHashScryptSalsa208SHA256.CustomComputePasswordHash(RandomPassword, 1048576, 33554432);
Boolean VerifyPassword = SodiumPasswordHashScryptSalsa208SHA256.VerifyPassword(HashedPasswordWithParams, RandomPassword);