module HexaPDF::Encryption::AES::ClassMethods

Convenience methods for decryption and encryption that operate according to the PDF specification.

These methods will be available on the class object that prepends the AES module.

Public Instance Methods

decrypt(key, data) { |error_message| ... }

Decrypts the given data using the key.

It is assumed that the initialization vector is included in the first BLOCK_SIZE bytes of the data. After the decryption the PKCS#5 padding is removed.

If a problem is encountered, an error message is yielded. If no block is given or if the supplied block returns true, an error is raised.

See: PDF2.0 s7.6.3

decryption_fiber(key, source) { |error_message| ... }

Returns a Fiber object that decrypts the data from the given source fiber with the key.

Padding, the initialization vector and an optionally given block are handled like in decrypt.

encrypt(key, data)

Encrypts the given data using the key and a randomly generated initialization vector.

The data is padded using the PKCS#5 padding scheme and the initialization vector is prepended to the encrypted data,

See: PDF2.0 s7.6.3

encryption_fiber(key, source)

Returns a Fiber object that encrypts the data from the given source fiber with the key.

Padding and the initialization vector are handled like in encrypt.

random_bytes(n)

Returns a string of n random bytes.

The specific AES algorithm class can override this class method to provide another method for generating random bytes.