public class InsecureNonceXChaCha20 extends Object
InsecureNonceXChaCha20 stream cipher based on
https://download.libsodium.org/doc/advanced/xchacha20.html and
https://tools.ietf.org/html/draft-arciszewski-xchacha-01.
This cipher is meant to be used to construct an AEAD with Poly1305. Specifically, it is only
intended to be used for scenarios that require user-supplied nonces, which would be insecure if
the user-supplied nonce ever repeats. Therefore, most users should prefer XChaCha20 instead, since it automatically supplies random nonce
inputs.
| Modifier and Type | Field and Description |
|---|---|
static int |
NONCE_SIZE_IN_BYTES |
| Constructor and Description |
|---|
InsecureNonceXChaCha20(byte[] key,
int initialCounter)
Constructs a new InsecureNonceXChaCha20 cipher with the supplied
key. |
| Modifier and Type | Method and Description |
|---|---|
byte[] |
decrypt(byte[] nonce,
byte[] ciphertext)
Decrypts
ciphertext using nonce. |
byte[] |
decrypt(byte[] nonce,
ByteBuffer ciphertext)
Decrypts
ciphertext using nonce. |
byte[] |
encrypt(byte[] nonce,
byte[] plaintext)
Encrypts
plaintext using nonce. |
void |
encrypt(ByteBuffer output,
byte[] nonce,
byte[] plaintext)
Encrypts
plaintext using nonce and writes result to output. |
public static final int NONCE_SIZE_IN_BYTES
public InsecureNonceXChaCha20(byte[] key,
int initialCounter)
throws InvalidKeyException
key.IllegalArgumentException - when key length is not ChaCha20Util.KEY_SIZE_IN_BYTES.InvalidKeyExceptionpublic byte[] encrypt(byte[] nonce,
byte[] plaintext)
throws GeneralSecurityException
plaintext using nonce.GeneralSecurityExceptionpublic void encrypt(ByteBuffer output, byte[] nonce, byte[] plaintext) throws GeneralSecurityException
plaintext using nonce and writes result to output.GeneralSecurityExceptionpublic byte[] decrypt(byte[] nonce,
byte[] ciphertext)
throws GeneralSecurityException
ciphertext using nonce.GeneralSecurityExceptionpublic byte[] decrypt(byte[] nonce,
ByteBuffer ciphertext)
throws GeneralSecurityException
ciphertext using nonce.GeneralSecurityException