klyn.cryptography.Cipher.aesEncrypt
method
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:
Description

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 KeyGenerator
  • random IV generation when iv is omitted
Parameters
ParameterDescription
plainTextSource text interpreted as UTF-8.
keyAES key material.
modeAES mode: GCM, CBC or CTR.
keyEncodingKey encoding: base64, base64url, hex or utf8.
ivOptional IV/nonce.
ivEncodingIV encoding when iv is provided.
aadOptional additional authenticated data for GCM.
Returns

Structured AES payload.

Throws
  • CryptoException when the inputs are invalid.
Example
import klyn.cryptography

key = AESKeyGenerator().generateKey()
payload = Cipher.aesEncrypt("hello", key)
print(payload.cipherTextBase64)