/// <summary> /// Initializes a new instance of the <see cref="AesCipher"/> class. /// </summary> /// <param name="key">The key.</param> /// <param name="mode">The mode.</param> /// <param name="padding">The padding.</param> /// <exception cref="ArgumentNullException"><paramref name="key"/> is null.</exception> /// <exception cref="ArgumentException">Keysize is not valid for this algorithm.</exception> public AesCipher(byte[] key, CipherMode mode, CipherPadding padding) : base(key, 16, mode, padding) { var keySize = key.Length * 8; if (!(keySize == 256 || keySize == 192 || keySize == 128)) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "KeySize '{0}' is not valid for this algorithm.", keySize)); } }
/// <summary> /// Initializes a new instance of the <see cref="CastCipher"/> class. /// </summary> /// <param name="key">The key.</param> /// <param name="mode">The mode.</param> /// <param name="padding">The padding.</param> /// <exception cref="ArgumentNullException"><paramref name="key"/> is null.</exception> /// <exception cref="ArgumentException">Keysize is not valid for this algorithm.</exception> public CastCipher(byte[] key, CipherMode mode, CipherPadding padding) : base(key, 8, mode, padding) { var keySize = key.Length * 8; if (!(keySize >= 40 && keySize <= 128 && keySize % 8 == 0)) { throw new ArgumentException(string.Format("KeySize '{0}' is not valid for this algorithm.", keySize)); } this.SetKey(key); }
private int _x0, _x1, _x2, _x3; // registers /// <summary> /// Initializes a new instance of the <see cref="SerpentCipher"/> class. /// </summary> /// <param name="key">The key.</param> /// <param name="mode">The mode.</param> /// <param name="padding">The padding.</param> /// <exception cref="ArgumentNullException"><paramref name="key"/> is null.</exception> /// <exception cref="ArgumentException">Keysize is not valid for this algorithm.</exception> public SerpentCipher(byte[] key, CipherMode mode, CipherPadding padding) : base(key, 16, mode, padding) { var keySize = key.Length * 8; if (!(keySize == 128 || keySize == 192 || keySize == 256)) { throw new ArgumentException(string.Format("KeySize '{0}' is not valid for this algorithm.", keySize)); } this._workingKey = this.MakeWorkingKey(key); }
/// <summary> /// Initializes a new instance of the <see cref="BlowfishCipher"/> class. /// </summary> /// <param name="key">The key.</param> /// <param name="mode">The mode.</param> /// <param name="padding">The padding.</param> /// <exception cref="ArgumentNullException"><paramref name="key"/> is null.</exception> /// <exception cref="ArgumentException">Keysize is not valid for this algorithm.</exception> public BlowfishCipher(byte[] key, CipherMode mode, CipherPadding padding) : base(key, 8, mode, padding) { var keySize = key.Length * 8; if (keySize < 1 || keySize > 448) { throw new ArgumentException(string.Format("KeySize '{0}' is not valid for this algorithm.", keySize)); } this._s0 = new uint[_sboxSk]; this._s1 = new uint[_sboxSk]; this._s2 = new uint[_sboxSk]; this._s3 = new uint[_sboxSk]; this._p = new uint[_pSize]; this.SetKey(key); }
/// <summary> /// Initializes a new instance of the <see cref="DesCipher"/> class. /// </summary> /// <param name="key">The key.</param> /// <param name="mode">The mode.</param> /// <param name="padding">The padding.</param> /// <exception cref="ArgumentNullException"><paramref name="key"/> is null.</exception> public DesCipher(byte[] key, CipherMode mode, CipherPadding padding) : base(key, 8, mode, padding) { }