C# 클래스 Liphsoft.Crypto.Argon2.PasswordHasher

PasswordHasher is a class for creating Argon2 hashes and verifying them. This is a wrapper around Daniel Dinu and Dmitry Khovratovich's Argon2 library.
상속: IPasswordHasher
파일 보기 프로젝트 열기: alipha/csharp-argon2 1 사용 예제들

공개 메소드들

메소드 설명
ExtractMetadata ( string formattedHash ) : HashMetadata

Extracts the memory cost, time cost, etc. used to generate the Argon2 hash. An encoded Argon2 hash created by the Hash method The hash metadata or null if the formattedHash was not a valid encoded Argon2 hash

GenerateSalt ( uint byteLength = 16 ) : byte[]

Generate salt using a Cryptographically-Secure Pseudo-Random Number Generator The number of bytes of salt to generate (default: 16) A array of randomly-generated bytes

Hash ( byte password ) : string

Hash the raw password bytes using Argon2 with a cryptographically-secure, random, 16-byte salt. Do not compare two Argon2 hashes directly. Instead, use the Verify or VerifyAndUpdate methods. The raw bytes of the password to be hashed A formatted string representing the hashed password, encoded with the parameters used to perform the hash

Hash ( byte password, byte salt ) : string

Hash the raw password bytes using Argon2 with the specified salt bytes. Unless you need to specify your own salt for interoperability purposes, prefer the Hash(byte[] password) overload instead. Do not compare two Argon2 hashes directly. Instead, use the Verify or VerifyAndUpdate methods. The raw bytes of the password to be hashed The raw salt bytes to be used for the hash. The salt must be at least 8 bytes. A formatted string representing the hashed password, encoded with the parameters used to perform the hash

Hash ( string password ) : string

Hash the password using Argon2 with a cryptographically-secure, random, 16-byte salt. This is the only overload of the Hash method that the typical user will need to use for password storage. The other overloads are provided for interoperability purposes. Do not compare two Argon2 hashes directly. Instead, use the Verify or VerifyAndUpdate methods. A string representing the password to be hashed. The password is first decoded into bytes using StringEncoding (default: Encoding.UTF8) A formatted string representing the hashed password, encoded with the parameters used to perform the hash

Hash ( string password, string salt ) : string

Hash the password using Argon2 with the specified salt. Unless you need to specify your own salt for interoperability purposes, prefer the Hash(string password) overload instead. Do not compare two Argon2 hashes directly. Instead, use the Verify or VerifyAndUpdate methods. A string representing the password to be hashed. The password is first decoded into bytes using StringEncoding (default: Encoding.UTF8) A string representing the salt to be used for the hash. The salt must be at least 8 bytes. The salt is first decoded into bytes using StringEncoding (default: Encoding.UTF8) A formatted string representing the hashed password, encoded with the parameters used to perform the hash

HashRaw ( byte password, byte salt ) : byte[]

Hash the password using Argon2 with the specified salt. The HashRaw methods may be used for password-based key derivation. Unless you're using HashRaw for key deriviation or for interoperability purposes, the Hash methods should be used in favor of the HashRaw methods. The raw bytes of the password to be hashed The raw salt bytes to be used for the hash. The salt must be at least 8 bytes. A byte array containing only the resulting hash

HashRaw ( string password, string salt ) : byte[]

Hash the password using Argon2 with the specified salt. The HashRaw methods may be used for password-based key derivation. Unless you're using HashRaw for key deriviation or for interoperability purposes, the Hash methods should be used in favor of the HashRaw methods. A string representing the password to be hashed. The password is first decoded into bytes using StringEncoding (default: Encoding.UTF8) A string representing the salt to be used for the hash. The salt must be at least 8 bytes. The salt is first decoded into bytes using StringEncoding (default: Encoding.UTF8) A byte array containing only the resulting hash

PasswordHasher ( UsageEnvironment environment ) : System

Initialize the Argon2 PasswordHasher with default performance and algorithm settings based upon the environment the hashing will be used in. You should perform your own profiling to determine what the parameters should be for your specific usage; however, this attempts to provide some reasonable defaults. Whether the PasswordHasher will be used in a server or single-user setting

PasswordHasher ( uint timeCost = 3, uint memoryCost = 8192, uint parallelism = 1, Argon2Type argonType = Argon2Type.Argon2i, uint hashLength = 32 ) : System

Initialize the Argon2 PasswordHasher with the performance and algorithm settings to use while hashing How many iterations of the Argon2 hash to perform (default: 3, must be at least 1) How much memory to use while hashing in kibibytes (KiB) (default: 8192 KiB [8 MiB], must be at least 8 KiB) How many threads to use while hashing (default: 1, must be at least 1) The type of Argon2 hashing algorithm to use (Independent [default] or Dependent) The length of the resulting hash in bytes (default: 32)

Verify ( string expectedHash, byte password ) : bool

Hashes the raw password bytes and verifies that the password results in the specified hash. The ArgonType must of this PasswordHasher object must match what was used to generate expectedHash. The other parameters (timeCost, etc.) do not need to match and the parameters embedded in the expectedHash will be used. Hashing the password should result in this hash The raw password bytes to hash and compare its result to expectedHash Whether the password results in the expectedHash when hashed

Verify ( string expectedHash, string password ) : bool

Hashes the password and verifies that the password results in the specified hash. The ArgonType must of this PasswordHasher object must match what was used to generate expectedHash. The other parameters (timeCost, etc.) do not need to match and the parameters embedded in the expectedHash will be used. Hashing the password should result in this hash The password to hash and compare its result to expectedHash. The password is first decoded into bytes using StringEncoding (default: Encoding.UTF8) Whether the password results in the expectedHash when hashed

VerifyAndUpdate ( string expectedHash, byte password, bool &isUpdated, string &newFormattedHash ) : bool

Hashes the password and verifies that the password results in the specified hash. (See Verify method) If the password verification is successful, this method checks to see if the memory cost, time cost, and parallelism match the parameters the PasswordHasher object was constructed with. If they do not much, then the password is rehashed using the new parameters and the result is outputted via the newFormattedHash parameter. Hashing the password should result in this hash The raw password bytes to hash and compare its result to expectedHash Whether the cost parameters of expectedHash differ from the PasswordHasher object and if the password was rehashed using th new parameters. This is always false if the password was incorrect. If isUpdated is true, then newFormattedHash is the password hashed with the new cost parameters. If isUpdated is false, then newFormattedHash is expectedHash. Whether the password results in the expectedHash when hashed

VerifyAndUpdate ( string expectedHash, string password, bool &isUpdated, string &newFormattedHash ) : bool

Hashes the password and verifies that the password results in the specified hash. (See Verify method) If the password verification is successful, this method checks to see if the memory cost, time cost, and parallelism match the parameters the PasswordHasher object was constructed with. If they do not much, then the password is rehashed using the new parameters and the result is outputted via the newFormattedHash parameter. Hashing the password should result in this hash The password to hash and compare its result to expectedHash. The password is first decoded into bytes using StringEncoding (default: Encoding.UTF8) Whether the cost parameters of expectedHash differ from the PasswordHasher object and if the password was rehashed using th new parameters. This is always false if the password was incorrect. If isUpdated is true, then newFormattedHash is the password hashed with the new cost parameters. If isUpdated is false, then newFormattedHash is expectedHash. Whether the password results in the expectedHash when hashed

비공개 메소드들

메소드 설명
CheckNull ( string methodName ) : void
crypto_argon2_hash ( uint t_cost, uint m_cost, uint parallelism, byte pwd, int pwdlen, byte salt, int saltlen, byte hash, int hashlen, byte encoded, int encodedlen, int type, int version ) : int
crypto_argon2_verify ( byte encoded, byte pwd, int pwdlen, int type ) : int
crypto_decode_string ( Argon2Context ctx, byte str, int type ) : int

메소드 상세

ExtractMetadata() 공개 정적인 메소드

Extracts the memory cost, time cost, etc. used to generate the Argon2 hash. An encoded Argon2 hash created by the Hash method The hash metadata or null if the formattedHash was not a valid encoded Argon2 hash
public static ExtractMetadata ( string formattedHash ) : HashMetadata
formattedHash string
리턴 HashMetadata

GenerateSalt() 공개 정적인 메소드

Generate salt using a Cryptographically-Secure Pseudo-Random Number Generator The number of bytes of salt to generate (default: 16) A array of randomly-generated bytes
public static GenerateSalt ( uint byteLength = 16 ) : byte[]
byteLength uint
리턴 byte[]

Hash() 공개 메소드

Hash the raw password bytes using Argon2 with a cryptographically-secure, random, 16-byte salt. Do not compare two Argon2 hashes directly. Instead, use the Verify or VerifyAndUpdate methods. The raw bytes of the password to be hashed A formatted string representing the hashed password, encoded with the parameters used to perform the hash
public Hash ( byte password ) : string
password byte
리턴 string

Hash() 공개 메소드

Hash the raw password bytes using Argon2 with the specified salt bytes. Unless you need to specify your own salt for interoperability purposes, prefer the Hash(byte[] password) overload instead. Do not compare two Argon2 hashes directly. Instead, use the Verify or VerifyAndUpdate methods. The raw bytes of the password to be hashed The raw salt bytes to be used for the hash. The salt must be at least 8 bytes. A formatted string representing the hashed password, encoded with the parameters used to perform the hash
public Hash ( byte password, byte salt ) : string
password byte
salt byte
리턴 string

Hash() 공개 메소드

Hash the password using Argon2 with a cryptographically-secure, random, 16-byte salt. This is the only overload of the Hash method that the typical user will need to use for password storage. The other overloads are provided for interoperability purposes. Do not compare two Argon2 hashes directly. Instead, use the Verify or VerifyAndUpdate methods. A string representing the password to be hashed. The password is first decoded into bytes using StringEncoding (default: Encoding.UTF8) A formatted string representing the hashed password, encoded with the parameters used to perform the hash
public Hash ( string password ) : string
password string
리턴 string

Hash() 공개 메소드

Hash the password using Argon2 with the specified salt. Unless you need to specify your own salt for interoperability purposes, prefer the Hash(string password) overload instead. Do not compare two Argon2 hashes directly. Instead, use the Verify or VerifyAndUpdate methods. A string representing the password to be hashed. The password is first decoded into bytes using StringEncoding (default: Encoding.UTF8) A string representing the salt to be used for the hash. The salt must be at least 8 bytes. The salt is first decoded into bytes using StringEncoding (default: Encoding.UTF8) A formatted string representing the hashed password, encoded with the parameters used to perform the hash
public Hash ( string password, string salt ) : string
password string
salt string
리턴 string

HashRaw() 공개 메소드

Hash the password using Argon2 with the specified salt. The HashRaw methods may be used for password-based key derivation. Unless you're using HashRaw for key deriviation or for interoperability purposes, the Hash methods should be used in favor of the HashRaw methods. The raw bytes of the password to be hashed The raw salt bytes to be used for the hash. The salt must be at least 8 bytes. A byte array containing only the resulting hash
public HashRaw ( byte password, byte salt ) : byte[]
password byte
salt byte
리턴 byte[]

HashRaw() 공개 메소드

Hash the password using Argon2 with the specified salt. The HashRaw methods may be used for password-based key derivation. Unless you're using HashRaw for key deriviation or for interoperability purposes, the Hash methods should be used in favor of the HashRaw methods. A string representing the password to be hashed. The password is first decoded into bytes using StringEncoding (default: Encoding.UTF8) A string representing the salt to be used for the hash. The salt must be at least 8 bytes. The salt is first decoded into bytes using StringEncoding (default: Encoding.UTF8) A byte array containing only the resulting hash
public HashRaw ( string password, string salt ) : byte[]
password string
salt string
리턴 byte[]

PasswordHasher() 공개 메소드

Initialize the Argon2 PasswordHasher with default performance and algorithm settings based upon the environment the hashing will be used in. You should perform your own profiling to determine what the parameters should be for your specific usage; however, this attempts to provide some reasonable defaults. Whether the PasswordHasher will be used in a server or single-user setting
public PasswordHasher ( UsageEnvironment environment ) : System
environment UsageEnvironment
리턴 System

PasswordHasher() 공개 메소드

Initialize the Argon2 PasswordHasher with the performance and algorithm settings to use while hashing How many iterations of the Argon2 hash to perform (default: 3, must be at least 1) How much memory to use while hashing in kibibytes (KiB) (default: 8192 KiB [8 MiB], must be at least 8 KiB) How many threads to use while hashing (default: 1, must be at least 1) The type of Argon2 hashing algorithm to use (Independent [default] or Dependent) The length of the resulting hash in bytes (default: 32)
public PasswordHasher ( uint timeCost = 3, uint memoryCost = 8192, uint parallelism = 1, Argon2Type argonType = Argon2Type.Argon2i, uint hashLength = 32 ) : System
timeCost uint
memoryCost uint
parallelism uint
argonType Argon2Type
hashLength uint
리턴 System

Verify() 공개 메소드

Hashes the raw password bytes and verifies that the password results in the specified hash. The ArgonType must of this PasswordHasher object must match what was used to generate expectedHash. The other parameters (timeCost, etc.) do not need to match and the parameters embedded in the expectedHash will be used. Hashing the password should result in this hash The raw password bytes to hash and compare its result to expectedHash Whether the password results in the expectedHash when hashed
public Verify ( string expectedHash, byte password ) : bool
expectedHash string
password byte
리턴 bool

Verify() 공개 메소드

Hashes the password and verifies that the password results in the specified hash. The ArgonType must of this PasswordHasher object must match what was used to generate expectedHash. The other parameters (timeCost, etc.) do not need to match and the parameters embedded in the expectedHash will be used. Hashing the password should result in this hash The password to hash and compare its result to expectedHash. The password is first decoded into bytes using StringEncoding (default: Encoding.UTF8) Whether the password results in the expectedHash when hashed
public Verify ( string expectedHash, string password ) : bool
expectedHash string
password string
리턴 bool

VerifyAndUpdate() 공개 메소드

Hashes the password and verifies that the password results in the specified hash. (See Verify method) If the password verification is successful, this method checks to see if the memory cost, time cost, and parallelism match the parameters the PasswordHasher object was constructed with. If they do not much, then the password is rehashed using the new parameters and the result is outputted via the newFormattedHash parameter. Hashing the password should result in this hash The raw password bytes to hash and compare its result to expectedHash Whether the cost parameters of expectedHash differ from the PasswordHasher object and if the password was rehashed using th new parameters. This is always false if the password was incorrect. If isUpdated is true, then newFormattedHash is the password hashed with the new cost parameters. If isUpdated is false, then newFormattedHash is expectedHash. Whether the password results in the expectedHash when hashed
public VerifyAndUpdate ( string expectedHash, byte password, bool &isUpdated, string &newFormattedHash ) : bool
expectedHash string
password byte
isUpdated bool
newFormattedHash string
리턴 bool

VerifyAndUpdate() 공개 메소드

Hashes the password and verifies that the password results in the specified hash. (See Verify method) If the password verification is successful, this method checks to see if the memory cost, time cost, and parallelism match the parameters the PasswordHasher object was constructed with. If they do not much, then the password is rehashed using the new parameters and the result is outputted via the newFormattedHash parameter. Hashing the password should result in this hash The password to hash and compare its result to expectedHash. The password is first decoded into bytes using StringEncoding (default: Encoding.UTF8) Whether the cost parameters of expectedHash differ from the PasswordHasher object and if the password was rehashed using th new parameters. This is always false if the password was incorrect. If isUpdated is true, then newFormattedHash is the password hashed with the new cost parameters. If isUpdated is false, then newFormattedHash is expectedHash. Whether the password results in the expectedHash when hashed
public VerifyAndUpdate ( string expectedHash, string password, bool &isUpdated, string &newFormattedHash ) : bool
expectedHash string
password string
isUpdated bool
newFormattedHash string
리턴 bool