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'.
Key |
A XChaCha20-Poly1305 key. class Key : Destroyable |
Nonce |
A XChaCha20-Poly1305 nonce. class Nonce |
decrypt |
Decrypt a message using a given key. 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? |
decryptDetached |
Decrypt a message using a given key and a detached message authentication code. 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? |
encrypt |
Encrypt a message for a given key. 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! |
encryptDetached |
Encrypt a message for a given key, generating a detached message authentication code. 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! |
isAvailable |
Check if Sodium and the XChaCha20Poly1305 algorithm is available. static fun isAvailable(): Boolean |
isSecretStreamAvailable |
Check if Sodium and the XChaCha20Poly1305 secret stream algorithm is available. static fun isSecretStreamAvailable(): Boolean |
openDecryptionStream |
Open an decryption stream. static fun openDecryptionStream(key: Key!, header: ByteArray!): SecretDecryptionStream! |
openEncryptionStream |
Open an encryption stream. static fun openEncryptionStream(key: Key!): SecretEncryptionStream! |