private void testSenderAndRecipientContexts(
      byte[] mode, byte[] kemId, byte[] kdfId, byte[] aeadId, HpkeParameters.KemId hpkeKem)
      throws GeneralSecurityException {
    HpkeTestVector testVector = getTestVector(mode, kemId, kdfId, aeadId);
    HpkeTestSetup testSetup = testVector.getTestSetup();

    HpkeKem kem = HpkePrimitiveFactory.createKem(kemId);
    HpkeKdf kdf = HpkePrimitiveFactory.createKdf(kdfId);
    HpkeAead aead = HpkePrimitiveFactory.createAead(aeadId);

    HpkeParameters hpkeParameters =
        HpkeParameters.builder()
            .setVariant(HpkeParameters.Variant.NO_PREFIX)
            .setKemId(hpkeKem)
            .setKdfId(HpkeParameters.KdfId.HKDF_SHA256)
            .setAeadId(HpkeParameters.AeadId.AES_128_GCM)
            .build();
    HpkePublicKey recipientPublicKey =
        HpkePublicKey.create(
            hpkeParameters,
            Bytes.copyFrom(testSetup.recipientPublicKey),
            /* idRequirement= */ null);
    HpkePrivateKey recipientPrivateKey =
        HpkePrivateKey.create(
            recipientPublicKey,
            SecretBytes.copyFrom(testSetup.recipientPrivateKey, InsecureSecretKeyAccess.get()));

    HpkeContext senderContext =
        HpkeContext.createSenderContext(
            recipientPublicKey.getPublicKeyBytes().toByteArray(), kem, kdf, aead, testSetup.info);

    HpkeKemPrivateKey recipientKemPrivateKey = HpkeKemKeyFactory.createPrivate(recipientPrivateKey);
    HpkeContext recipientContext =
        HpkeContext.createRecipientContext(
            senderContext.getEncapsulatedKey(),
            recipientKemPrivateKey,
            kem,
            kdf,
            aead,
            testSetup.info);

    byte[] plaintext = Random.randBytes(200);
    byte[] aad = Random.randBytes(100);
    byte[] ciphertext = senderContext.seal(plaintext, aad);
    expect.that(recipientContext.open(ciphertext, aad)).isEqualTo(plaintext);
  }
Helper method to verify context API provided to Tink users.
java_src/src/test/java/com/google/crypto/tink/hybrid/internal/HpkeContextTest.java