encrypt
Encrypts a String and returns a Base64-encoded ciphertext.
Classical (AES-GCM) — no salt
val cipher = "Hello Kindling!".encrypt(
key = KEncryptKeyType.Classical("my-secret")
)Content copied to clipboard
Classical with salt
val cipher = "Hello Kindling!".encrypt(
key = KEncryptKeyType.Classical("my-secret", KHashAlgorithm.SHA256),
salt = "random-salt"
)Content copied to clipboard
Post-quantum (Kyber-1024)
val pair = KEncryptKeyPair.generate()
val cipher = "Hello Kindling!".encrypt(
key = KEncryptKeyType.PostQuantum(publicKeyBase64 = pair.publicKeyBase64)
)Content copied to clipboard
Return
Base64-encoded ciphertext (includes IV/nonce prepended).
Parameters
key
The key type and material to use.
salt
Optional salt string mixed into the key derivation (classical only).
Low-level ByteArray encryption. Returns raw ciphertext bytes.
Prefer the String.encrypt extension for everyday use.