Beryl::Crypto::Compatibility::AdvancedEncryptionStandardInCipherBlockChainingMode
AES in cipher block chaining mode with PKCS#7 padding (FIPS 197, NIST SP 800-38A §6.2, RFC 5652 §6.3), under a 16, 24 or 32-byte key.
CBC keeps a message private and does nothing to prove it is whole:
anyone can alter the ciphertext, and a receiver that reports bad padding
helps an attacker read it. It is here to read and write formats that
already use it (Amber's version 1 cookies, Grant's version 1 encrypted
attributes), which authenticate the ciphertext with HMAC before they
decrypt. New designs use Beryl::Crypto.encrypt.
cipher = Beryl::Crypto::Compatibility::AESCBC.new(key)
ciphertext = cipher.encrypt("a private note", initialization_vector: initialization_vector)
cipher.decrypt(ciphertext, initialization_vector: initialization_vector) # => the note's bytes, or nil
Constants
Constructors
Instance methods
Returns the plaintext of ciphertext, or nil when the ciphertext is
empty, is not a whole number of blocks, or decrypts to malformed
padding. The padding is checked in constant time; whether it was well
formed, and how long it was, is what this method returns.
Decrypts ciphertext into padded_plaintext, which must be as long,
and returns how many of its first bytes are the plaintext; or returns
nil, with padded_plaintext wiped, when the ciphertext is empty, is
not a whole number of blocks, or decrypts to malformed padding.
Returns plaintext, padded to a whole number of blocks, encrypted under initialization_vector (16 bytes, fresh and unpredictable for every message).