openssh_key.cipher.confidentiality.CBCCipher

class openssh_key.cipher.confidentiality.CBCCipher

Bases: openssh_key.cipher.confidentiality.ConfidentialityOnlyCipher, abc.ABC

A cipher under the cipher block chaining mode of operation.

__init__()

Methods

ALGORITHM()

rtype

CipherAlgorithm

MODE()

__init__()

decrypt(kdf, passphrase, cipher_bytes)

Decrypts the given ciphertext bytes using the given options of a key derivation function and the given passphrase to derive the encryption key.

decrypt_with_key_iv(cipher_bytes, ...)

Decrypts the given ciphertext bytes using the given cipher key and initialization vector.

encrypt(kdf, passphrase, plain_bytes)

Encrypts the given plaintext bytes using the given options of a key derivation function and the given passphrase to derive the encryption key.

encrypt_with_key_iv(plain_bytes, cipher_key, ...)

Encrypts the given plaintext bytes using the given cipher key and initialization vector.

get_algorithm()

The encryption algorithm of this cipher.

get_block_size()

The block size for this cipher.

get_iv_length()

The initialization vector length for this cipher in bytes.

get_key_length()

The key length for this cipher in bytes.

get_mode()

The cipher block chaining mode of operation.

Attributes

BLOCK_SIZE

The block size for this cipher.

IV_LENGTH

The initialization vector length for this cipher in bytes.

KEY_LENGTH

The key length for this cipher in bytes.

classmethod decrypt(kdf, passphrase, cipher_bytes)

Decrypts the given ciphertext bytes using the given options of a key derivation function and the given passphrase to derive the encryption key.

Parameters
  • kdf (KDFOptions) – The options of a key derivation function.

  • passphrase (str) – The passphrase from which the cipher key is derived.

  • cipher_bytes (bytes) – Ciphertext bytes to be decrypted.

Return type

bytes

Returns

Plaintext bytes.

classmethod decrypt_with_key_iv(cipher_bytes, cipher_key, initialization_vector)

Decrypts the given ciphertext bytes using the given cipher key and initialization vector.

Parameters
  • cipher_bytes (bytes) – Ciphertext bytes to be encrypted.

  • cipher_key (bytes) – The cipher key.

  • initialization_vector (bytes) – The initialization vector. For some ciphers, this need only be a nonce.

Return type

bytes

Returns

Plaintext bytes.

classmethod encrypt(kdf, passphrase, plain_bytes)

Encrypts the given plaintext bytes using the given options of a key derivation function and the given passphrase to derive the encryption key.

Parameters
  • kdf (KDFOptions) – The options of a key derivation function.

  • passphrase (str) – The passphrase from which the cipher key is derived.

  • plain_bytes (bytes) – Plaintext bytes to be encrypted.

Return type

bytes

Returns

Ciphertext bytes.

classmethod encrypt_with_key_iv(plain_bytes, cipher_key, initialization_vector)

Encrypts the given plaintext bytes using the given cipher key and initialization vector.

Parameters
  • plain_bytes (bytes) – Plaintext bytes to be encrypted.

  • cipher_key (bytes) – The cipher key.

  • initialization_vector (bytes) – The initialization vector. For some ciphers, this need only be a nonce.

Return type

bytes

Returns

Ciphertext bytes.

abstract classmethod get_algorithm()

The encryption algorithm of this cipher.

Return type

Callable[[bytes], CipherAlgorithm]

abstract classmethod get_block_size()

The block size for this cipher.

Return type

int

abstract classmethod get_iv_length()

The initialization vector length for this cipher in bytes. Defaults to the block size.

Return type

int

abstract classmethod get_key_length()

The key length for this cipher in bytes.

Return type

int

classmethod get_mode()

The cipher block chaining mode of operation.

Return type

Callable[[bytes], Mode]