class XChaCha20Poly1305
(source)
Authenticated Encryption with Additional Data using XChaCha20-Poly1305.
The XChaCha20-Poly1305 construction can safely encrypt a practically unlimited number of messages with the same key, without any practical limit to the size of a message (up to ~ 2^64 bytes).
As an alternative to counters, its large nonce size (192-bit) allows random nonces to be safely used.
For this reason, and if interoperability with other libraries is not a concern, this is the recommended AEAD construction.
This class depends upon the JNR-FFI library being available on the classpath, along with its dependencies. See https://github.com/jnr/jnr-ffi. JNR-FFI can be included using the gradle dependency 'com.github.jnr:jnr-ffi'.
class Key : Destroyable
A XChaCha20-Poly1305 key. |
|
class Nonce
A XChaCha20-Poly1305 nonce. |
static fun decrypt(cipherText: Bytes, key: Key, nonce: Nonce): Bytes? static fun decrypt(cipherText: ByteArray, key: Key, nonce: Nonce): ByteArray? static fun decrypt(cipherText: Bytes, data: Bytes, key: Key, nonce: Nonce): Bytes? static fun decrypt(cipherText: ByteArray, data: ByteArray, key: Key, nonce: Nonce): ByteArray?
Decrypt a message using a given key. |
|
static fun decryptDetached(cipherText: Bytes, mac: Bytes, key: Key, nonce: Nonce): Bytes static fun decryptDetached(cipherText: ByteArray, mac: ByteArray, key: Key, nonce: Nonce): ByteArray? static fun decryptDetached(cipherText: Bytes, mac: Bytes, data: Bytes, key: Key, nonce: Nonce): Bytes? static fun decryptDetached(cipherText: ByteArray, mac: ByteArray, data: ByteArray, key: Key, nonce: Nonce): ByteArray?
Decrypt a message using a given key and a detached message authentication code. |
|
static fun encrypt(message: Bytes, key: Key, nonce: Nonce): Bytes static fun encrypt(message: ByteArray, key: Key, nonce: Nonce): ByteArray static fun encrypt(message: Bytes, data: Bytes, key: Key, nonce: Nonce): Bytes static fun encrypt(message: ByteArray, data: ByteArray, key: Key, nonce: Nonce): ByteArray
Encrypt a message for a given key. |
|
static fun encryptDetached(message: Bytes, key: Key, nonce: Nonce): DetachedEncryptionResult static fun encryptDetached(message: ByteArray, key: Key, nonce: Nonce): DetachedEncryptionResult static fun encryptDetached(message: Bytes, data: Bytes, key: Key, nonce: Nonce): DetachedEncryptionResult static fun encryptDetached(message: ByteArray, data: ByteArray, key: Key, nonce: Nonce): DetachedEncryptionResult
Encrypt a message for a given key, generating a detached message authentication code. |
|
static fun isAvailable(): Boolean
Check if Sodium and the XChaCha20Poly1305 algorithm is available. XChaCha20Poly1305 is supported in sodium native library version >= 10.0.12. |
|
static fun isSecretStreamAvailable(): Boolean
Check if Sodium and the XChaCha20Poly1305 secret stream algorithm is available. XChaCha20Poly1305 secret stream is supported in sodium native library version >= 10.0.14. |
|
static fun openDecryptionStream(key: Key, header: ByteArray): SecretDecryptionStream
Open an decryption stream. |
|
static fun openEncryptionStream(key: Key): SecretEncryptionStream
Open an encryption stream. |