Cipher.named constructor

Cipher.named(
  1. String algorithm,
  2. List<int> key
)

Any unauthenticated cipher EVP_CIPHER_fetch knows, e.g. AES-256-CBC, ChaCha20.

Throws ArgumentError for AEAD modes (AES-256-GCM, ChaCha20-Poly1305, CCM, OCB, SIV): this class never produces or checks a tag, so it would silently emit unauthenticated output. Use Aead for those. Throws OpenSSLException for a name the provider does not know.

Implementation

factory Cipher.named(String algorithm, List<int> key) {
  final cipher = Cipher._(algorithm, Uint8List.fromList(key));
  final flags = cipher._withCipher((c) => ssl.EVP_CIPHER_get_flags(c));
  if (flags & ssl.EVP_CIPH_FLAG_AEAD_CIPHER != 0) {
    throw ArgumentError.value(
      algorithm,
      'algorithm',
      'is an AEAD cipher; Cipher never handles authentication tags, '
          'use Aead instead',
    );
  }
  return cipher;
}