Encrypt data with the key and the parameters set at initialization.
The cipher object is stateful; encryption of a long block
of data can be broken up in two or more calls to encrypt().
That is, the statement:
>>> c.encrypt(a) + c.encrypt(b)
is always equivalent to:
>>> c.encrypt(a+b)
That also means that you cannot reuse an object for encrypting
or decrypting other data with the same key.
This function does not perform any padding.
- For MODE_ECB, MODE_CBC, and MODE_OFB, plaintext length
(in bytes) must be a multiple of block_size.
- For MODE_CFB, plaintext length (in bytes) must be a multiple
of segment_size/8.
- For MODE_CTR, plaintext can be of any length.
- For MODE_OPENPGP, plaintext must be a multiple of block_size,
unless it is the last chunk of the message.
- 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 with MODE_OPENPGP, the encypted IV is prepended to the
returned ciphertext.
|