encrypt

@JvmName(name = "encryptWithAutoGenIV")
suspend fun <K : KeyType, A : AuthCapability<out K>, I : NonceTrait> SymmetricKey<A, I, out K>.encrypt(    data: ByteArray): KmmResult<SealedBox<A, I, out K>>(source)

Encrypts data and automagically generates a fresh nonce/IV if required by the cipher.

Return

KmmResult.success containing a SealedBox if valid parameters were provided or KmmResult.failure in case of invalid parameters (e.g., algorithm mismatch, key length, …)


@JvmName(name = "encryptAuthenticated")
suspend fun <K : KeyType, A : AuthCapability.Authenticated<out K>, I : NonceTrait> SymmetricKey<A, I, out K>.encrypt(    data: ByteArray,     authenticatedData: ByteArray? = null): KmmResult<SealedBox<A, I, out K>>(source)

Encrypts data and automagically generates a fresh nonce/IV if required by the cipher.

Return

KmmResult.success containing a SealedBox if valid parameters were provided or KmmResult.failure in case of invalid parameters (e.g., algorithm mismatch, key length, …)

Parameters

authenticatedData

Additional data to be authenticated (i.e. fed into the auth tag generation) but not encrypted.

-

It is safe to discard the reference to this data, as the SealedBox resulting from this operation will carry the corresponding type information.