// Validate "rgbKey" and "rgbIV" values for a call on // "CreateDecryptor" or "CreateEncryptor". internal void ValidateCreate(byte[] rgbKey, byte[] rgbIV) { if (rgbKey == null) { throw new ArgumentNullException("rgbKey"); } KeySizes.Validate(LegalKeySizesValue, rgbKey.Length * 8, "Crypto_InvalidKeySize"); if (rgbIV != null) { // Verify the size of the IV against the block size. if ((rgbIV.Length * 8) != BlockSizeValue) { throw new CryptographicException (_("Crypto_InvalidIVSize"), rgbIV.Length.ToString()); } } else if (ModeValue != CipherMode.ECB) { // We must have an IV in every mode except ECB. throw new ArgumentNullException("rgbIV"); } }
// Determine if a key size is valid. public bool ValidKeySize(int bitLength) { return(KeySizes.Validate(LegalKeySizesValue, bitLength)); }