/// <summary>
 /// Encodes everything needed to store a password hash
 /// so that its associated password can be verified later.
 /// </summary>
 /// <param name="passwordSalt">
 /// The password salt in the form of a byte array.
 /// </param>
 /// <param name="passwordHash">
 /// The password hash in the form of a byte array.
 /// </param>
 /// <param name="hashPolicy">
 /// The hash policy. This is used to extract the hash
 /// algorithm, the hash work factor, and the hash
 /// storage format.
 /// </param>
 /// <returns>
 /// ASCII string in the format ".AAAA.BBBB.NNNN.XXXX.YYYY"
 /// where . = delimiter character, AAAA = hash algorithm,
 /// BBBB = encoding format, NNNN = work factor,
 /// XXXX = encoded password salt, YYYY = encoded password hash.
 /// </returns>
 public string HashEncode(byte[] passwordSalt, byte[] passwordHash, HashPolicy hashPolicy)
 {
     this.PasswordSalt      = ValidatePasswordSalt(passwordSalt);
     this.PasswordHash      = ValidatePasswordHash(passwordHash);
     this.HashMethod        = hashPolicy.HashMethod;
     this.WorkFactor        = hashPolicy.WorkFactor;
     this.HashStorageFormat = hashPolicy.HashStorageFormat;
     return(this.StoredHash);
 }
Exemplo n.º 2
0
 /// <summary>
 /// Use the specified hash policy.
 /// </summary>
 public HashGenerator(HashPolicy hashPolicy)
 {
     this.Policy = hashPolicy;
 }
 /// <summary>
 /// Encodes everything needed to store a password hash
 /// so that its associated password can be verified later.
 /// </summary>
 /// <param name="passwordSalt">
 /// The password salt in the form of a Unicode string.
 /// </param>
 /// <param name="passwordHash">
 /// The password hash in the form of a Unicode string.
 /// </param>
 /// <param name="hashPolicy">
 /// The hash policy. This is used to extract the hash
 /// algorithm, the hash work factor, and the hash
 /// storage format.
 /// </param>
 /// <returns>
 /// ASCII string in the format ".AAAA.BBBB.NNNN.XXXX.YYYY"
 /// where . = delimiter character, AAAA = hash algorithm,
 /// BBBB = encoding format, NNNN = work factor,
 /// XXXX = encoded password salt, YYYY = encoded password hash.
 /// </returns>
 public string HashEncode(string passwordSalt, string passwordHash, HashPolicy hashPolicy)
 {
     return(this.HashEncode(Encoding.UTF8.GetBytes(passwordSalt), Encoding.UTF8.GetBytes(passwordHash), hashPolicy));
 }