Beispiel #1
0
    /// <summary>
    /// Generates a cryptographic key from a password.
    /// </summary>
    /// <param name="password">The password.</param>
    /// <param name="keySize">The cipher key size. 256-bit is stronger, but slower.</param>
    /// <returns>The cryptographic key.</returns>
    public static byte[] GenerateKey(string password, KeySize keySize) {
      // Create a salt to help prevent rainbow table attacks
      var salt = Hash.Pbkdf2(password, Hash.Sha512(password + password.Length), Settings.HashIterations);

      // Generate a key from the password and salt
      return Hash.Pbkdf2(password, salt, Settings.HashIterations, (int)keySize / 8);
    }
Beispiel #2
0
 /// <summary>
 /// Calculates the MAC for a ciphertext.
 /// </summary>
 /// <param name="ciphertext">The ciphertext.</param>
 /// <param name="key">The key.</param>
 /// <returns>The MAC.</returns>
 public static byte[] CalculateMac(byte[] ciphertext, byte[] key)
 {
     return(Hash.Pbkdf2(ciphertext, key, Settings.HashIterations));
 }