public static aesEncrypt(plainText as String, key as String, mode as String = "GCM", keyEncoding as String = "base64", iv as String = null, ivEncoding as String = "base64", aad as String = null) as AESCipherText throws CryptoException:
Encrypts text with AES.
Supported modes are GCM, CBC and CTR.
Defaults are optimized for the common case:
mode = "GCM"keyEncoding = "base64" so it works directly with KeyGeneratoriv is omitted| Parameter | Description |
|---|---|
plainText | Source text interpreted as UTF-8. |
key | AES key material. |
mode | AES mode: GCM, CBC or CTR. |
keyEncoding | Key encoding: base64, base64url, hex or utf8. |
iv | Optional IV/nonce. |
ivEncoding | IV encoding when iv is provided. |
aad | Optional additional authenticated data for GCM. |
Structured AES payload.
import klyn.cryptography
key = AESKeyGenerator().generateKey()
payload = Cipher.aesEncrypt("hello", key)
print(payload.cipherTextBase64)