key is a base64-encoded 256-bit AES key (call crypt.generatekey() to make one).
iv is a base64-encoded 16-byte initialization vector.
Default mode is "CBC". Other accepted modes: "ECB", "CTR", "CFB", "OFB", "GCM". Learn more here.
Parameters
Returns
(string, string) - a tuple of (ciphertext, IV) where both are base64-encoded. The IV is returned even when the caller provided one, so the value can always be stored or transmitted alongside the ciphertext.
Example
Cache some sensitive data to disk so the next script run can reuse it without re-fetching.Encrypt it first so anyone who copies or shares the file can’t read the value.