public CipherInfo(SymmetricAlgorithm algorithm, int keySize, CipherModeEx mode) { Contract.Requires(algorithm != null); Contract.Requires(algorithm.LegalKeySizes.Any(x => x.MinSize <= keySize && keySize <= x.MaxSize && keySize % x.SkipSize == 0)); algorithm.KeySize = keySize; KeySize = algorithm.KeySize; BlockSize = algorithm.BlockSize; Cipher = (key, vi, isEncryption) => new EncryptionAlgorithm(algorithm, keySize, mode, key, vi, isEncryption); }
public EncryptionAlgorithm(SymmetricAlgorithm algorithm, int keySize, CipherModeEx mode, byte[] key, byte[] iv, bool isEncryption) { Contract.Requires(algorithm != null); Contract.Requires(key != null); Contract.Requires(iv != null); Contract.Requires(keySize == key.Length << 3); algorithm.KeySize = keySize; algorithm.Key = key; algorithm.IV = iv; algorithm.Padding = PaddingMode.None; _algorithm = algorithm; _mode = mode; _transform = CreateTransform(isEncryption); }