public static BlowfishCipher CreateEks(byte[] key, byte[] salt, int cost) { Helper.CheckRange("key", key, 1, 72); Helper.CheckRange("salt", salt, 16, 16); Helper.CheckRange("cost", cost, 4, 31); BlowfishCipher fish = new BlowfishCipher(); fish.ExpandKey(key, salt); for (uint i = 1u << cost; i > 0; i--) { fish.ExpandKey(key, ZeroSalt); fish.ExpandKey(salt, ZeroSalt); } return(fish); }
/// <summary> /// Performs an Expensive Key Schedule (EKS) Blowfish key expansion and /// creates a Blowfish cipher using the result. Flags may modify the key expansion. /// </summary> /// <param name="key"> /// The key. This must be between 1 and 72 bytes. /// Unlike <see cref="BlowfishCrypter"/>, this method does NOT automatically add a null byte to the key. /// </param> /// <param name="salt">The salt. This must be 16 bytes.</param> /// <param name="cost"> /// The expansion cost. This is a value between 4 and 31, /// specifying the logarithm of the number of iterations. /// </param> /// <param name="flags">Flags modifying the key expansion.</param> /// <returns>A Blowfish cipher.</returns> public static BlowfishCipher CreateEks(byte[] key, byte[] salt, int cost, EksBlowfishKeyExpansionFlags flags) { Check.Length("key", key, 1, 72); Check.Length("salt", salt, 16, 16); Check.Range("cost", cost, 4, 31); BlowfishCipher fish = new BlowfishCipher(null, null); fish.ExpandKey(key, salt, flags); for (uint i = 1u << cost; i > 0; i--) { fish.ExpandKey(key, _zeroSalt, flags); fish.ExpandKey(salt, _zeroSalt, EksBlowfishKeyExpansionFlags.None); } return(fish); }
public static BlowfishCipher Create(byte[] key) { Helper.CheckRange("key", key, 4, 56); BlowfishCipher fish = new BlowfishCipher(); fish.ExpandKey(key, ZeroSalt); return(fish); }
/// <summary> /// Creates a Blowfish cipher using the provided key. /// </summary> /// <param name="key">The Blowfish key. This must be between 4 and 56 bytes.</param> /// <returns>A Blowfish cipher.</returns> public static BlowfishCipher Create(byte[] key) { Check.Length("key", key, 4, 56); BlowfishCipher fish = new BlowfishCipher(null, null); fish.ExpandKey(key, _zeroSalt, EksBlowfishKeyExpansionFlags.None); return(fish); }