public void encrypt(
      ByteBuffer output, final byte[] nonce, final byte[] plaintext, final byte[] associatedData)
      throws GeneralSecurityException {
    if (output.remaining() < plaintext.length + MAC_TAG_SIZE_IN_BYTES) {
      throw new IllegalArgumentException("Given ByteBuffer output is too small");
    }
    int firstPosition = output.position();
    chacha20.encrypt(output, nonce, plaintext);
    output.position(firstPosition);
    output.limit(output.limit() - MAC_TAG_SIZE_IN_BYTES);
    byte[] aad = associatedData;
    if (aad == null) {
      aad = new byte[0];
    }
    byte[] tag = Poly1305.computeMac(getMacKey(nonce), macDataRfc8439(aad, output));
    output.limit(output.limit() + MAC_TAG_SIZE_IN_BYTES);
    output.put(tag);
  }
Encrypts {@code plaintext} with Poly1305 authentication based on {@code associatedData}.

<p>Please note that nonce should be randomly generated by the caller hence keys need to be
rotated after encrypting a certain number of messages depending on the nonce size of the
underlying {@link InsecureNonceChaCha20Base}.

@param output ciphertext buffer with the following format {@code actual_ciphertext || tag}
@param nonce specified by caller
@param plaintext data to encrypt
@param associatedData associated authenticated data
java_src/src/main/java/com/google/crypto/tink/aead/internal/InsecureNonceChaCha20Poly1305Base.java