Argon2.HashPassword Method
Namespace: Rebex.Security.Cryptography
Assembly: Rebex.Security.dll (version 7.0.9083)
HashPassword(ArraySegment<Byte>, ArraySegment<Byte>, Int32, Argon2Configuration)
Computes a hash of the specified password
and returns it in encoded form.
The format of the encoded hash is described in the remarks section of Argon2 class documentation.
Declaration
public static string HashPassword(ArraySegment<byte> password, ArraySegment<byte> salt, int hashLength, Argon2Configuration configuration)
Parameters
Type | Name | Description |
---|---|---|
ArraySegment<Byte> | password | The ArraySegment<T> that contains a password to hash. 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.
When the |
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 |
---|---|
String | A string that contains an encoded hash of the |
Examples
public string HashPassword(ArraySegment<byte> password, ArraySegment<byte> salt)
{
// Convert password to a byte array segment.
var passwordBytes = new ArraySegment<byte>(Encoding.UTF8.GetBytes(password));
// Use Argon2 configuration suitable for your environment.
var configuration = new Argon2Configuration(argon2Type: Argon2Type.Argon2id,
numberOfLanes: 4, numberOfIterations: 10, memoryCost: 65536);
// The size of the raw hash to compute. Must be at least 4 bytes long.
// Please note that the encoded hash (in string form) will be longer than the raw hash.
int hashLength = 32;
// Compute the hash of the password.
string encodedHash = Argon2.HashPassword(passwordBytes, salt, hashLength, configuration);
// Return the computed hash. Encoded hash has the following structure:
// $argon2id$v=19$m=65536,t=10,p=4$MTIzNDU2Nzg$GVfTf0x89BTwcW7HhQMYRcgPwOzswaw6UUBWDBXP0kc
return encodedHash;
}
Exceptions
Type | Condition |
---|---|
ArgumentNullException | The |
ArgumentException | The |
ArgumentOutOfRangeException | The |
See Also
HashPassword(String, ArraySegment<Byte>, Int32, Argon2Configuration)
Computes a hash of the specified password
and returns it in encoded form.
The format of the encoded hash is described in the remarks section of Argon2 class documentation.
Declaration
public static string HashPassword(string password, ArraySegment<byte> salt, int hashLength, Argon2Configuration configuration)
Parameters
Type | Name | Description |
---|---|---|
String | password | The string that contains a password to hash. Parameter 'P' from Argon2 specification.
The |
ArraySegment<Byte> | salt | The ArraySegment<T> that contains the salt. Must be at least 8 bytes long. Parameter 'S' from Argon2 specification.
When the |
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 |
---|---|
String | A string that contains an encoded hash of the |
Examples
public string HashPassword(string password, ArraySegment<byte> salt)
{
// Use Argon2 configuration suitable for your environment.
var configuration = new Argon2Configuration(argon2Type: Argon2Type.Argon2id,
numberOfLanes: 4, numberOfIterations: 10, memoryCost: 65536);
// The size of the raw hash to compute. Must be at least 4 bytes long.
// Please note that the encoded hash (in string form) will be longer than the raw hash.
int hashLength = 32;
// Compute the hash of the password.
string encodedHash = Argon2.HashPassword(password, salt, hashLength, configuration);
// Return the computed hash. Encoded hash has the following structure:
// $argon2id$v=19$m=65536,t=10,p=4$MTIzNDU2Nzg$GVfTf0x89BTwcW7HhQMYRcgPwOzswaw6UUBWDBXP0kc
return encodedHash;
}
Exceptions
Type | Condition |
---|---|
ArgumentNullException | The |
ArgumentException | The |
ArgumentOutOfRangeException | The |
See Also
HashPassword(ArraySegment<Byte>, Int32, Argon2Configuration)
Computes a hash of the specified password
and returns it in encoded form.
The method generates a random (16 bytes long) salt (parameter 'S' from Argon2 specification) before hashing.
The format of the encoded hash is described in the remarks section of Argon2 class documentation.
Declaration
public static string HashPassword(ArraySegment<byte> password, int hashLength, Argon2Configuration configuration)
Parameters
Type | Name | Description |
---|---|---|
ArraySegment<Byte> | password | The ArraySegment<T> that contains a password to hash. Parameter 'P' 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 |
---|---|
String | A string that contains an encoded hash of the |
Examples
public string HashPassword(ArraySegment<byte> password)
{
// Use Argon2 configuration suitable for your environment.
var configuration = new Argon2Configuration(argon2Type: Argon2Type.Argon2id,
numberOfLanes: 4, numberOfIterations: 10, memoryCost: 65536);
// The size of the raw hash to compute. Must be at least 4 bytes long.
// Please note that the encoded hash (in string form) will be longer than the raw hash.
int hashLength = 32;
// Compute the hash of the password.
// This method generates a random (16 bytes long) salt value.
string encodedHash = Argon2.HashPassword(password, hashLength, configuration);
// Return the computed hash. Encoded hash has the following structure.
// $argon2id$v=19$m=65536,t=10,p=4$MTIzNDU2Nzg$GVfTf0x89BTwcW7HhQMYRcgPwOzswaw6UUBWDBXP0kc
return encodedHash;
}
Exceptions
Type | Condition |
---|---|
ArgumentNullException | The |
ArgumentOutOfRangeException | The |
See Also
HashPassword(String, Int32, Argon2Configuration)
Computes a hash of the specified password
and returns it in encoded form.
The method generates a random (16 bytes long) salt (parameter 'S' from Argon2 specification) before hashing.
The format of the encoded hash is described in the remarks section of Argon2 class documentation.
Declaration
public static string HashPassword(string password, int hashLength, Argon2Configuration configuration)
Parameters
Type | Name | Description |
---|---|---|
String | password | The string that contains a password to hash. Parameter 'P' from Argon2 specification.
The |
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 |
---|---|
String | A string that contains an encoded hash of the |
Examples
public string HashPassword(string password)
{
// Use Argon2 configuration suitable for your environment.
var configuration = new Argon2Configuration(argon2Type: Argon2Type.Argon2id,
numberOfLanes: 4, numberOfIterations: 10, memoryCost: 65536);
// The size of the raw hash to compute. Must be at least 4 bytes long.
// Please note that the encoded hash (in string form) will be longer than the raw hash.
int hashLength = 32;
// Compute the hash of the password.
// This method generates a random (16 bytes long) salt value.
string encodedHash = Argon2.HashPassword(password, hashLength, configuration);
// Return the computed hash. Encoded hash has the following structure.
// $argon2id$v=19$m=65536,t=10,p=4$MTIzNDU2Nzg$GVfTf0x89BTwcW7HhQMYRcgPwOzswaw6UUBWDBXP0kc
return encodedHash;
}
Exceptions
Type | Condition |
---|---|
ArgumentNullException | The |
ArgumentOutOfRangeException | The |
See Also
HashPassword(Byte[], Byte[], Int32, Argon2Configuration)
Computes a hash of the specified password
and returns it in encoded form.
The format of the encoded hash is described in the remarks section of Argon2 class documentation.
Declaration
public static string HashPassword(byte[] password, byte[] salt, int hashLength, Argon2Configuration configuration)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | password | The byte array that contains a password to hash. Parameter 'P' from Argon2 specification.
When the |
Byte[] | salt | The byte array that contains the salt. Must be at least 8 bytes long. Parameter 'S' from Argon2 specification.
When the |
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 |
---|---|
String | A string that contains an encoded hash of the |
Examples
public string HashPassword(string password, byte[] salt)
{
// Convert password to a byte array.
byte[] passwordBytes = Encoding.UTF8.GetBytes(password);
// Use Argon2 configuration suitable for your environment.
var configuration = new Argon2Configuration(argon2Type: Argon2Type.Argon2id,
numberOfLanes: 4, numberOfIterations: 10, memoryCost: 65536);
// The size of the raw hash to compute. Must be at least 4 bytes long.
// Please note that the encoded hash (in string form) will be longer than the raw hash.
int hashLength = 32;
// Compute the hash of the password.
string encodedHash = Argon2.HashPassword(passwordBytes, salt, hashLength, configuration);
// Return the computed hash. Encoded hash has the following structure:
// $argon2id$v=19$m=65536,t=10,p=4$MTIzNDU2Nzg$GVfTf0x89BTwcW7HhQMYRcgPwOzswaw6UUBWDBXP0kc
return encodedHash;
}
Exceptions
Type | Condition |
---|---|
ArgumentNullException | The |
ArgumentException | The |
ArgumentOutOfRangeException | The |
See Also
HashPassword(String, Byte[], Int32, Argon2Configuration)
Computes a hash of the specified password
and returns it in encoded form.
The format of the encoded hash is described in the remarks section of Argon2 class documentation.
Declaration
public static string HashPassword(string password, byte[] salt, int hashLength, Argon2Configuration configuration)
Parameters
Type | Name | Description |
---|---|---|
String | password | The string that contains a password to hash. Parameter 'P' from Argon2 specification.
The |
Byte[] | salt | The byte array that contains the salt. Must be at least 8 bytes long. Parameter 'S' from Argon2 specification.
When the |
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 |
---|---|
String | A string that contains an encoded hash of the |
Examples
public string HashPassword(string password, byte[] salt)
{
// Use Argon2 configuration suitable for your environment.
var configuration = new Argon2Configuration(argon2Type: Argon2Type.Argon2id,
numberOfLanes: 4, numberOfIterations: 10, memoryCost: 65536);
// The size of the raw hash to compute. Must be at least 4 bytes long.
// Please note that the encoded hash (in string form) will be longer than the raw hash.
int hashLength = 32;
// Compute the hash of the password.
string encodedHash = Argon2.HashPassword(password, salt, hashLength, configuration);
// Return the computed hash. Encoded hash has the following structure:
// $argon2id$v=19$m=65536,t=10,p=4$MTIzNDU2Nzg$GVfTf0x89BTwcW7HhQMYRcgPwOzswaw6UUBWDBXP0kc
return encodedHash;
}
Exceptions
Type | Condition |
---|---|
ArgumentNullException | The |
ArgumentException | The |
ArgumentOutOfRangeException | The |
See Also
HashPassword(Byte[], Int32, Argon2Configuration)
Computes a hash of the specified password
and returns it in encoded form.
Generates a random (16 bytes long) salt (parameter 'S' from Argon2 specification) before hashing.
The format of the encoded hash is described in the remarks section of Argon2 class documentation.
Declaration
public static string HashPassword(byte[] password, int hashLength, Argon2Configuration configuration)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | password | The byte array that contains a password to hash. Parameter 'P' from Argon2 specification.
When the |
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 |
---|---|
String | A string that contains an encoded hash of the |
Examples
public string HashPassword(string password)
{
// Convert password to a byte array.
byte[] passwordBytes = Encoding.UTF8.GetBytes(password);
// Use Argon2 configuration suitable for your environment.
var configuration = new Argon2Configuration(argon2Type: Argon2Type.Argon2id,
numberOfLanes: 4, numberOfIterations: 10, memoryCost: 65536);
// The size of the raw hash to compute. Must be at least 4 bytes long.
// Please note that the encoded hash (in string form) will be longer than the raw hash.
int hashLength = 32;
// Compute the hash of the password.
// This method generates a random 16-bytes long salt value.
string encodedHash = Argon2.HashPassword(passwordBytes, hashLength, configuration);
// Return the computed hash. Encoded hash has the following structure:
// $argon2id$v=19$m=65536,t=10,p=4$MTIzNDU2Nzg$GVfTf0x89BTwcW7HhQMYRcgPwOzswaw6UUBWDBXP0kc
return encodedHash;
}
Exceptions
Type | Condition |
---|---|
ArgumentNullException | The |
ArgumentOutOfRangeException | The |