Class InsecureNonceChaCha20Poly1305Jce


  • @Immutable
    public final class InsecureNonceChaCha20Poly1305Jce
    extends java.lang.Object
    Implements ChaCha20Poly1305, as described in RFC 8439, section 2.8.

    It is similar to ChaCha20Poly1305Jce, but it offers an interface for the user to choose the nonce, which is needed in HPKE.

    It uses the JCE, and requires that algorithm "ChaCha20-Poly1305" is present.

    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static InsecureNonceChaCha20Poly1305Jce create​(byte[] key)  
      byte[] decrypt​(byte[] nonce, byte[] ciphertext, byte[] associatedData)
      Decrypts ciphertext with nonce and associatedData.
      byte[] decrypt​(byte[] nonce, byte[] ciphertextWithPrefix, int ciphertextOffset, byte[] associatedData)
      Decrypts ciphertextWithPrefix with nonce and associatedData.
      byte[] encrypt​(byte[] nonce, byte[] plaintext, byte[] associatedData)
      Encrypts plaintext with nonce and associatedData.
      byte[] encrypt​(byte[] nonce, byte[] plaintext, int ciphertextOffset, byte[] associatedData)
      Encrypts plaintext with nonce and associatedData.
      static boolean isSupported()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • create

        public static InsecureNonceChaCha20Poly1305Jce create​(byte[] key)
                                                       throws java.security.GeneralSecurityException
        Throws:
        java.security.GeneralSecurityException
      • isSupported

        public static boolean isSupported()
      • encrypt

        public byte[] encrypt​(byte[] nonce,
                              byte[] plaintext,
                              byte[] associatedData)
                       throws java.security.GeneralSecurityException
        Encrypts plaintext with nonce and associatedData.
        Throws:
        java.security.GeneralSecurityException
      • encrypt

        public byte[] encrypt​(byte[] nonce,
                              byte[] plaintext,
                              int ciphertextOffset,
                              byte[] associatedData)
                       throws java.security.GeneralSecurityException
        Encrypts plaintext with nonce and associatedData.

        The ciphertextOffset is the offset at which the ciphertext will start in the returned byte array.

        Throws:
        java.security.GeneralSecurityException
      • decrypt

        public byte[] decrypt​(byte[] nonce,
                              byte[] ciphertext,
                              byte[] associatedData)
                       throws java.security.GeneralSecurityException
        Decrypts ciphertext with nonce and associatedData.
        Throws:
        java.security.GeneralSecurityException
      • decrypt

        public byte[] decrypt​(byte[] nonce,
                              byte[] ciphertextWithPrefix,
                              int ciphertextOffset,
                              byte[] associatedData)
                       throws java.security.GeneralSecurityException
        Decrypts ciphertextWithPrefix with nonce and associatedData.

        The ciphertextOffset is the offset at which the ciphertext starts in the ciphertextWithPrefix.

        Throws:
        java.security.GeneralSecurityException