java_src/src/main/java/com/google/crypto/tink/subtle/ChaCha20Poly1305Base.java
/**
   * Encrypts the {@code plaintext} with Poly1305 authentication based on {@code associatedData}.
   *
   * <p>Please note that nonce is randomly generated hence keys need to be rotated after encrypting
   * a certain number of messages depending on the nonce size of the underlying {@link
   * ChaCha20Base}.
   *
   * @param plaintext data to encrypt
   * @param associatedData associated authenticated data
   * @return ciphertext with the following format {@code nonce || actual_ciphertext || tag}
   */
Encrypts the  plaintext with Poly1305 authentication based on  associatedData.
Please note that nonce is randomly generated hence keys need to be rotated after encrypting
a certain number of messages depending on the nonce size of the underlying {@link
ChaCha20Base}.

@param plaintext data to encrypt
@param associatedData associated authenticated data
@return ciphertext with the following format  nonce || actual_ciphertext || tag
Encrypts the plaintext with Poly1305 authentication based on associatedData . Please note that nonce is randomly generated hence keys need to be rotated after encrypting a certain number of messages depending on the nonce size of the underlying { @link ChaCha20Base } . @param plaintext data to encrypt @param associatedData associated authenticated data @return ciphertext with the following format nonce || actual_ciphertext || tag
@Override
  public byte[] encrypt(final byte[] plaintext, final byte[] associatedData)
      throws GeneralSecurityException {
    if (plaintext.length
        > Integer.MAX_VALUE - chacha20.nonceSizeInBytes() - MAC_TAG_SIZE_IN_BYTES) {
      throw new GeneralSecurityException("plaintext too long");
    }
    ByteBuffer ciphertext =
        ByteBuffer.allocate(plaintext.length + chacha20.nonceSizeInBytes() + MAC_TAG_SIZE_IN_BYTES);
    encrypt(ciphertext, plaintext, associatedData);
    return ciphertext.array();
  }
@ Override public byte [ ] encrypt ( final byte [ ] plaintext , final byte [ ] associatedData ) throws GeneralSecurityException { if ( plaintext . length > Integer . MAX_VALUE - chacha20 . nonceSizeInBytes ( ) - MAC_TAG_SIZE_IN_BYTES ) { throw new GeneralSecurityException ( "plaintext too long" ) ; } ByteBuffer ciphertext = ByteBuffer . allocate ( plaintext . length + chacha20 . nonceSizeInBytes ( ) + MAC_TAG_SIZE_IN_BYTES ) ; encrypt ( ciphertext , plaintext , associatedData ) ; return ciphertext . array ( ) ; }
Encrypts the {@code plaintext} with Poly1305 authentication based on {@code associatedData}.
Encrypts the { @code plaintext } with Poly1305 authentication based on { @code associatedData } .