public byte[] decrypt(ByteBuffer ciphertext, final byte[] nonce, final byte[] associatedData)
      throws GeneralSecurityException {
    if (ciphertext.remaining() < MAC_TAG_SIZE_IN_BYTES) {
      throw new GeneralSecurityException("ciphertext too short");
    }
    int firstPosition = ciphertext.position();
    byte[] tag = new byte[MAC_TAG_SIZE_IN_BYTES];
    ciphertext.position(ciphertext.limit() - MAC_TAG_SIZE_IN_BYTES);
    ciphertext.get(tag);
    // rewind to read ciphertext and compute tag.
    ciphertext.position(firstPosition);
    ciphertext.limit(ciphertext.limit() - MAC_TAG_SIZE_IN_BYTES);
    byte[] aad = associatedData;
    if (aad == null) {
      aad = new byte[0];
    }
    try {
      Poly1305.verifyMac(getMacKey(nonce), macDataRfc8439(aad, ciphertext), tag);
    } catch (GeneralSecurityException ex) {
      throw new AEADBadTagException(ex.toString());
    }

    // rewind to decrypt the ciphertext.
    ciphertext.position(firstPosition);
    return chacha20.decrypt(nonce, ciphertext);
  }
Decrypts {@code ciphertext} with the following format: {@code actual_ciphertext || tag}.

@param ciphertext with format {@code actual_ciphertext || tag}
@param nonce specified by caller
@param associatedData associated authenticated data
@return plaintext if authentication is successful
@throws GeneralSecurityException when ciphertext is shorter than tag size
@throws AEADBadTagException when the tag is invalid
java_src/src/main/java/com/google/crypto/tink/aead/internal/InsecureNonceChaCha20Poly1305Base.java