public void TestArgumentExceptions() { using (var rc4 = new RC4()) { var buffer = new byte[16]; Assert.AreEqual(1, rc4.InputBlockSize, "InputBlockSize"); Assert.AreEqual(1, rc4.OutputBlockSize, "OutputBlockSize"); Assert.IsFalse(rc4.CanReuseTransform, "CanReuseTransform"); Assert.IsTrue(rc4.CanTransformMultipleBlocks, "CanTransformMultipleBlocks"); Assert.Throws <InvalidOperationException> (() => { var x = rc4.Key; }); Assert.Throws <ArgumentNullException> (() => { rc4.Key = null; }); Assert.Throws <ArgumentException> (() => { rc4.Key = new byte[0]; }); rc4.GenerateIV(); rc4.GenerateKey(); rc4.CreateDecryptor(); rc4.CreateEncryptor(); // TransformBlock input buffer parameters Assert.Throws <ArgumentNullException> (() => rc4.TransformBlock(null, 0, buffer.Length, buffer, 0)); Assert.Throws <ArgumentOutOfRangeException> (() => rc4.TransformBlock(buffer, -1, buffer.Length, buffer, 0)); Assert.Throws <ArgumentOutOfRangeException> (() => rc4.TransformBlock(buffer, 0, -1, buffer, 0)); // TransformBlock output buffer parameters Assert.Throws <ArgumentNullException> (() => rc4.TransformBlock(buffer, 0, buffer.Length, null, 0)); Assert.Throws <ArgumentOutOfRangeException> (() => rc4.TransformBlock(buffer, 0, buffer.Length, buffer, -1)); // TransformFinalBlock Assert.Throws <ArgumentNullException> (() => rc4.TransformFinalBlock(null, 0, buffer.Length)); Assert.Throws <ArgumentOutOfRangeException> (() => rc4.TransformFinalBlock(buffer, -1, buffer.Length)); Assert.Throws <ArgumentOutOfRangeException> (() => rc4.TransformFinalBlock(buffer, 0, -1)); } }
public Crypt(int keySize) { RC4 = new RC4 { KeySize = keySize }; RC4.GenerateKey(); }
public EncryptContext(int keySize) { RC4 = new RC4 { KeySize = keySize }; RC4.GenerateKey(); }
public Crypt(int keySize, int fastKeySize) { if (keySize == 0) { AES = new RijndaelManaged { BlockSize = s_defaultKey.Length * 8, KeySize = s_defaultKey.Length * 8, Padding = PaddingMode.None, Mode = CipherMode.ECB, Key = s_defaultKey }; } else { AES = new RijndaelManaged { BlockSize = keySize, KeySize = keySize, Padding = PaddingMode.None, Mode = CipherMode.ECB }; AES.GenerateKey(); } if (fastKeySize == 0) { RC4 = new RC4 { KeySize = s_defaultKey.Length * 8, Key = s_defaultKey }; } else { RC4 = new RC4 { KeySize = fastKeySize }; RC4.GenerateKey(); } }