Argon2.HashData Method
Namespace: Rebex.Security.Cryptography
Assembly: Rebex.Security.dll (version 7.0.9083)
HashData(ArraySegment<Byte>, ArraySegment<Byte>, ArraySegment<Byte>, ArraySegment<Byte>, ArraySegment<Byte>, Argon2Configuration)
Computes a hash using Argon2 memory-hard hash algorithm.
Declaration
public static int HashData(ArraySegment<byte> source, ArraySegment<byte> salt, ArraySegment<byte> key, ArraySegment<byte> associatedData, ArraySegment<byte> destination, Argon2Configuration configuration)
Parameters
Type | Name | Description |
---|---|---|
ArraySegment<Byte> | source | The ArraySegment<T> that contains data (password) to be hashed. The 'P' parameter from Argon2 specification. |
ArraySegment<Byte> | salt | The ArraySegment<T> that contains the salt. Must be at least 8 bytes long. Parameter 'S' from Argon2 specification. |
ArraySegment<Byte> | key | The ArraySegment<T> that contains key (secret). Parameter 'K' from Argon2 specification. Can be empty. |
ArraySegment<Byte> | associatedData | The ArraySegment<T> that contains associated data. Parameter 'X' from Argon2 specification. Can be empty. |
ArraySegment<Byte> | destination | The ArraySegment<T> that will receive the calculated hash. Must be at least 4 bytes long. |
Argon2Configuration | configuration | Argon2 configuration. |
Returns
Type | Description |
---|---|
Int32 | The number of bytes written to |
Examples
public ArraySegment<byte> HashData()
{
// Data to be hashed.
ArraySegment<byte> sourceData = GetSourceData();
// Prepare salt. Must be at least 8 bytes long.
ArraySegment<byte> salt = GetSalt();
// Prepare key. Can be empty.
ArraySegment<byte> key = GetKey();
// Prepare associated data. Can be empty.
ArraySegment<byte> associatedData = GetAssociatedData();
// Use Argon2 configuration suitable for your environment.
var configuration = new Argon2Configuration(argon2Type: Argon2Type.Argon2id,
numberOfLanes: 1, numberOfIterations: 4, memoryCost: 4096 /*KB*/);
// Create the destination ArraySegment which will receive the computed hash.
// Must be at least 4 bytes long, although a larger size is recommended.
var outputHash = new ArraySegment<byte>(new byte[32]);
// Compute the hash. Returns the hash size in bytes (32 in this case).
int hashLength = Argon2.HashData(sourceData,
salt,
key,
associatedData,
outputHash,
configuration);
// Return the computed hash for further processing.
return outputHash;
}
Exceptions
Type | Condition |
---|---|
ArgumentNullException | The |
ArgumentException | The |
HashData(ArraySegment<Byte>, ArraySegment<Byte>, ArraySegment<Byte>, Argon2Configuration)
Computes a hash using Argon2 memory-hard hash algorithm.
Declaration
public static int HashData(ArraySegment<byte> source, ArraySegment<byte> salt, ArraySegment<byte> destination, Argon2Configuration configuration)
Parameters
Type | Name | Description |
---|---|---|
ArraySegment<Byte> | source | The ArraySegment<T> that contains data (password) to be hashed. Parameter 'P' from Argon2 specification. |
ArraySegment<Byte> | salt | The ArraySegment<T> that contains the salt. Must be at least 8 bytes long. Parameter 'S' from Argon2 specification. |
ArraySegment<Byte> | destination | The ArraySegment<T> that will receive the calculated hash. Must be at least 4 bytes long. |
Argon2Configuration | configuration | Argon2 configuration. |
Returns
Type | Description |
---|---|
Int32 | The number of bytes written to |
Examples
public ArraySegment<byte> HashData()
{
// Data to be hashed.
ArraySegment<byte> sourceData = GetSourceData();
// Prepare salt. Must be at least 8 bytes long.
ArraySegment<byte> salt = GetSalt();
// Use Argon2 configuration suitable for your environment.
var configuration = new Argon2Configuration(argon2Type: Argon2Type.Argon2id,
numberOfLanes: 1, numberOfIterations: 4, memoryCost: 4096 /*KB*/);
// Create the destination ArraySegment which will receive the computed hash.
// Must be at least 4 bytes long, although a larger size is recommended.
var outputHash = new ArraySegment<byte>(new byte[32]);
// Compute the hash. Returns the hash size in bytes (32 in this case).
int hashLength = Argon2.HashData(sourceData,
salt,
outputHash,
configuration);
// Return the computed hash for further processing.
return outputHash;
}
Exceptions
Type | Condition |
---|---|
ArgumentNullException | The |
ArgumentException | The |
HashData(ArraySegment<Byte>, ArraySegment<Byte>, Int32, Argon2Configuration)
Computes a hash using Argon2 memory-hard hash algorithm.
Declaration
public static byte[] HashData(ArraySegment<byte> source, ArraySegment<byte> salt, int hashLength, Argon2Configuration configuration)
Parameters
Type | Name | Description |
---|---|---|
ArraySegment<Byte> | source | The ArraySegment<T> that contains data (password) to be hashed. Parameter 'P' from Argon2 specification. |
ArraySegment<Byte> | salt | The ArraySegment<T> that contains the salt. Must be at least 8 bytes long. Parameter 'S' from Argon2 specification. |
Int32 | hashLength | The required hash length. Must be at least 4 bytes long. Parameter 'T' from Argon2 specification. |
Argon2Configuration | configuration | Argon2 configuration. |
Returns
Type | Description |
---|---|
Byte[] | A byte array that contains the computed hash. |
Examples
public byte[] HashData()
{
// Data to be hashed.
ArraySegment<byte> sourceData = GetSourceData();
// Prepare salt. Must be at least 8 bytes long.
ArraySegment<byte> salt = GetSalt();
// Use Argon2 configuration suitable for your environment.
var configuration = new Argon2Configuration(argon2Type: Argon2Type.Argon2id,
numberOfLanes: 1, numberOfIterations: 4, memoryCost: 4096 /*KB*/);
// The size of the hash to compute. Must be at least 4 bytes long.
int requiredHashSize = 32;
// Compute the hash.
byte[] hash = Argon2.HashData(sourceData,
salt,
requiredHashSize,
configuration);
// Return the computed hash for further processing.
return hash;
}
Exceptions
Type | Condition |
---|---|
ArgumentNullException | The |
ArgumentException | The |
ArgumentOutOfRangeException | The |
HashData(Byte[], Byte[], Int32, Argon2Configuration)
Computes a hash using Argon2 memory-hard hash algorithm.
Declaration
public static byte[] HashData(byte[] source, byte[] salt, int hashLength, Argon2Configuration configuration)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | source | The byte array that contains data (password) to be hashed. Parameter 'P' from Argon2 specification. |
Byte[] | salt | The byte array that contains the salt. Must be at least 8 bytes long. Parameter 'S' from Argon2 specification. |
Int32 | hashLength | The required hash length. Must be at least 4 bytes long. Parameter 'T' from Argon2 specification. |
Argon2Configuration | configuration | Argon2 configuration. |
Returns
Type | Description |
---|---|
Byte[] | A byte array that contains the computed hash. |
Examples
public byte[] HashData()
{
// Data to be hashed.
byte[] sourceData = GetSourceData();
// Prepare salt. Must be at least 8 bytes long.
byte[] salt = GetSalt();
// Use Argon2 configuration suitable for your environment.
var configuration = new Argon2Configuration(argon2Type: Argon2Type.Argon2id,
numberOfLanes: 1, numberOfIterations: 4, memoryCost: 4096 /*KB*/);
// The size of the hash to compute. Must be at least 4 bytes long.
int requiredHashSize = 32;
// Compute the hash.
byte[] hash = Argon2.HashData(sourceData,
salt,
requiredHashSize,
configuration);
// Return the computed hash for further processing.
return hash;
}
Exceptions
Type | Condition |
---|---|
ArgumentNullException | The |
ArgumentException | The |
ArgumentOutOfRangeException | The |