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; }
/// <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); }
/// <summary>Initializes the instance with a (new) key string.</summary> /// <param name="keyStr">The key material.</param> /// <see cref="BlowfishSimple(String)"/> public void Initialize(String keyStr) { byte[] keyRaw = TransformKey(keyStr); HashAlgorithm sha = new SHA1CryptoServiceProvider(); byte[] key = sha.ComputeHash(keyRaw); byte[] checksumSalt = new byte[20]; this.rng.GetBytes(checksumSalt); byte[] checksum = CalcKeyChecksum(checksumSalt, keyRaw); byte[] checksumCombo = new byte[checksumSalt.Length + checksum.Length]; Array.Copy( checksumSalt, 0, checksumCombo, 0, checksumSalt.Length); Array.Copy( checksum, 0, checksumCombo, checksumSalt.Length, checksum.Length); this.keyChecksum = Convert.ToBase64String(checksumCombo); this.bfc = new BlowfishCBC(key, 0, key.Length); Array.Clear(keyRaw, 0, keyRaw.Length); Array.Clear(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; }