Use make-cipher to create an object for encryption and decryption.
Signature
(make-cipher name &key key mode initialization-vector padding tweak) => cipher
Parameters
name: The algorithm (e.g., :aes, ironclad:arcfour). Use (list-all-ciphers) to see all supported names.mode: The mode of operation (e.g., :ecb, :cbc, :ctr, :stream).key: A (simple-array (unsigned-byte 8) (*)).initialization-vector: A (simple-array (unsigned-byte 8) (*)) of the cipher's block length. For Chacha/Salsa20, use 8 or 12 bytes; for XChacha/XSalsa20, use 24 bytes.padding: Supported for ECB/CBC modes: :pkcs7, :ansi-x923, :iso-7816-4.tweak: Supported by certain ciphers like threefish.
Encryption and Decryption
Standard API
(encrypt cipher plaintext ciphertext &key plaintext-start plaintext-end ciphertext-start handle-final-block)
(decrypt cipher ciphertext plaintext &key ciphertext-start ciphertext-end plaintext-start handle-final-block)
Note: handle-final-block is required if using padding.
In-place API
(encrypt-in-place cipher text &key start end)
(decrypt-in-place cipher text &key start end)
Note: In-place functions do not support handle-final-block.
Message API
(encrypt-message cipher message &key start end &allow-other-keys)
(decrypt-message cipher message &key start end &allow-other-keys)
(let ((key (make-array 32 :element-type '(unsigned-byte 8) :initial-element 0))
(iv (make-array 16 :element-type '(unsigned-byte 8) :initial-element 0))
(p (make-array 16 :element-type '(unsigned-byte 8) :initial-element 1))
(c (make-array 16 :element-type '(unsigned-byte 8))))
(let ((cipher (make-cipher :aes :key key :mode :cbc :initialization-vector iv :padding :pkcs7)))
(encrypt cipher p c :handle-final-block t)
(decrypt cipher c p :handle-final-block t)))