Class InsecureNonceXChaCha20
- java.lang.Object
-
- com.google.crypto.tink.aead.internal.InsecureNonceXChaCha20
-
public class InsecureNonceXChaCha20 extends java.lang.ObjectInsecureNonceXChaCha20stream 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
XChaCha20instead, since it automatically supplies random nonce inputs.
-
-
Field Summary
Fields Modifier and Type Field Description static intNONCE_SIZE_IN_BYTES
-
Constructor Summary
Constructors Constructor Description InsecureNonceXChaCha20(byte[] key, int initialCounter)Constructs a new InsecureNonceXChaCha20 cipher with the suppliedkey.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]decrypt(byte[] nonce, byte[] ciphertext)Decryptsciphertextusingnonce.byte[]decrypt(byte[] nonce, java.nio.ByteBuffer ciphertext)Decryptsciphertextusingnonce.byte[]encrypt(byte[] nonce, byte[] plaintext)Encryptsplaintextusingnonce.voidencrypt(java.nio.ByteBuffer output, byte[] nonce, byte[] plaintext)Encryptsplaintextusingnonceand writes result tooutput.
-
-
-
Field Detail
-
NONCE_SIZE_IN_BYTES
public static final int NONCE_SIZE_IN_BYTES
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
InsecureNonceXChaCha20
public InsecureNonceXChaCha20(byte[] key, int initialCounter) throws java.security.InvalidKeyExceptionConstructs a new InsecureNonceXChaCha20 cipher with the suppliedkey.- Throws:
java.lang.IllegalArgumentException- whenkeylength is notChaCha20Util.KEY_SIZE_IN_BYTES.java.security.InvalidKeyException
-
-
Method Detail
-
encrypt
public byte[] encrypt(byte[] nonce, byte[] plaintext) throws java.security.GeneralSecurityExceptionEncryptsplaintextusingnonce.- Throws:
java.security.GeneralSecurityException
-
encrypt
public void encrypt(java.nio.ByteBuffer output, byte[] nonce, byte[] plaintext) throws java.security.GeneralSecurityExceptionEncryptsplaintextusingnonceand writes result tooutput.- Throws:
java.security.GeneralSecurityException
-
decrypt
public byte[] decrypt(byte[] nonce, byte[] ciphertext) throws java.security.GeneralSecurityExceptionDecryptsciphertextusingnonce.- Throws:
java.security.GeneralSecurityException
-
decrypt
public byte[] decrypt(byte[] nonce, java.nio.ByteBuffer ciphertext) throws java.security.GeneralSecurityExceptionDecryptsciphertextusingnonce.- Throws:
java.security.GeneralSecurityException
-
-