Package Cryptodome :: Package Cipher :: Module _mode_openpgp :: Class OpenPgpMode

Class OpenPgpMode

object --+
         |
        OpenPgpMode

OpenPGP mode.

This mode is a variant of CFB, and it is only used in PGP and OpenPGP applications. If in doubt, use another mode.

An Initialization Vector (IV) is required.

Unlike CFB, the encrypted IV (not the IV itself) is transmitted to the receiver.

The IV is a random data block. For legacy reasons, two of its bytes are duplicated to act as a checksum for the correctness of the key, which is now known to be insecure and is ignored. The encrypted IV is therefore 2 bytes longer than the clean IV.

Instance Methods
 
encrypt(self, plaintext)
Encrypt data with the key and the parameters set at initialization.
 
decrypt(self, ciphertext)
Decrypt data with the key and the parameters set at initialization.

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __init__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Instance Variables
  block_size
The block size of the underlying cipher, in bytes.
Properties

Inherited from object: __class__

Method Details

encrypt(self, plaintext)

 

Encrypt data with the key and the parameters set at initialization.

A cipher object is stateful: once you have encrypted a message you cannot encrypt (or decrypt) another message using the same object.

The data to encrypt can be broken up in two or more pieces and encrypt can be called multiple times.

That is, the statement:

>>> c.encrypt(a) + c.encrypt(b)

is equivalent to:

>>> c.encrypt(a+b)

This function does not add any padding to the plaintext.

Parameters:
  • plaintext (byte string) - The piece of data to encrypt.
Returns:
the encrypted data, as a byte string. It is as long as plaintext with one exception: when encrypting the first message chunk, the encypted IV is prepended to the returned ciphertext.

decrypt(self, ciphertext)

 

Decrypt data with the key and the parameters set at initialization.

A cipher object is stateful: once you have decrypted a message you cannot decrypt (or encrypt) another message with the same object.

The data to decrypt can be broken up in two or more pieces and decrypt can be called multiple times.

That is, the statement:

>>> c.decrypt(a) + c.decrypt(b)

is equivalent to:

>>> c.decrypt(a+b)

This function does not remove any padding from the plaintext.

Parameters:
  • ciphertext (byte string) - The piece of data to decrypt.
Returns:
the decrypted data (byte string).