private BlowfishAlgorithm(byte[] key, byte[] iv, bool useCBC, bool isEncryptor) { if (null == key) { GenerateKey(); } else { Key = key; } if (useCBC) { IV = this.origIV = iv; this.bfc = new BlowfishCBC(KeyValue, 0, KeyValue.Length); this.bfc.SetIV(IVValue, 0); } else { this.bfe = new BlowfishECB(KeyValue, 0, KeyValue.Length); } this.isEncryptor = isEncryptor; }
/// <summary>Creates a new BlowfishEasy instance. Notice that this ctor /// supports only the new way of how string are set up. There is no support /// for the old BlowfishJ key setup available right now (which had a /// design flaw by not using the full Unicode character space).</summary> /// <param name="password">The password used for encryption and decryption.</param> public BlowfishEasy(String password) { int c = password.Length; byte[] passw = new byte[c << 1]; for (int i = 0, j = 0; i < c; i++) { int chr = (int)password[i]; passw[j++] = (byte)((chr >> 8) & 0x0ff); passw[j++] = (byte)(chr & 0x0ff); } SHA1 sha = new SHA1Managed(); byte[] key = sha.ComputeHash(passw); this.bfc = new BlowfishCBC(key, 0, key.Length); }
/// <summary>Creates a new BlowfishEasy instance. Notice that this ctor /// supports only the new way of how string are set up. There is no support /// for the old BlowfishJ key setup available right now (which had a /// design flaw by not using the full Unicode character space).</summary> /// <param name="password">The password used for encryption and decryption.</param> public BlowfishEasy(String password) { int c = password.Length; byte[] passw = new byte[c << 1]; for (int i = 0, j = 0; i < c; i++) { int chr = (int)password[i]; passw[j++] = (byte)((chr >> 8) & 0x0ff); passw[j++] = (byte)( chr & 0x0ff); } SHA1 sha = new SHA1Managed(); byte[] key = sha.ComputeHash(passw); this.bfc = new BlowfishCBC(key, 0, key.Length); }
/// <see cref="BlowfishNET.BlowfishECB.Clone"/> public new object Clone() { BlowfishCBC result; result = new BlowfishCBC(); result.pbox = (uint[]) this.pbox.Clone(); result.sbox1 = (uint[]) this.sbox1.Clone(); result.sbox2 = (uint[]) this.sbox2.Clone(); result.sbox3 = (uint[]) this.sbox3.Clone(); result.sbox4 = (uint[]) this.sbox4.Clone(); result.block = (byte[]) this.block.Clone(); result.isWeakKey = this.isWeakKey; result.ivHi = this.ivHi; result.ivLo = this.ivLo; return result; }
/// <see cref="BlowfishNET.BlowfishECB.Clone"/> public new object Clone() { BlowfishCBC result; result = new BlowfishCBC(); result.pbox = (uint[])this.pbox.Clone(); result.sbox1 = (uint[])this.sbox1.Clone(); result.sbox2 = (uint[])this.sbox2.Clone(); result.sbox3 = (uint[])this.sbox3.Clone(); result.sbox4 = (uint[])this.sbox4.Clone(); result.block = (byte[])this.block.Clone(); result.isWeakKey = this.isWeakKey; result.ivHi = this.ivHi; result.ivLo = this.ivLo; return(result); }