decrypt

fun String.decrypt(key: KEncryptKeyType, salt: String? = null): String(source)

Decrypts a Base64-encoded ciphertext produced by encrypt.

Classical

val plain = cipherText.decrypt(
key = KEncryptKeyType.Classical("my-secret"),
salt = "random-salt" // must match the salt used during encryption
)

Post-quantum

val plain = cipherText.decrypt(
key = KEncryptKeyType.PostQuantum(
publicKeyBase64 = pair.publicKeyBase64,
privateKeyBase64 = pair.privateKeyBase64
)
)

Return

Decrypted plaintext string.

Parameters

key

The key type and material to use.

salt

Optional salt; must match the value used during encrypt.

Throws

if decryption fails (wrong key, wrong salt, corrupted data…).


Low-level ByteArray decryption. Returns raw plaintext bytes.

Prefer the String.decrypt extension for everyday use.