@Test
  public void getOutputPrefix() throws Exception {
    HpkeParameters.Builder paramsBuilder =
        HpkeParameters.builder()
            .setKemId(HpkeParameters.KemId.DHKEM_X25519_HKDF_SHA256)
            .setKdfId(HpkeParameters.KdfId.HKDF_SHA256)
            .setAeadId(HpkeParameters.AeadId.AES_128_GCM);
    Bytes publicKeyBytes = Bytes.copyFrom(X25519.publicFromPrivate(X25519.generatePrivateKey()));

    HpkeParameters noPrefixParams =
        paramsBuilder.setVariant(HpkeParameters.Variant.NO_PREFIX).build();
    HpkePublicKey noPrefixPublicKey =
        HpkePublicKey.create(noPrefixParams, publicKeyBytes, /* idRequirement= */ null);
    assertThat(noPrefixPublicKey.getIdRequirementOrNull()).isEqualTo(null);
    assertThat(noPrefixPublicKey.getOutputPrefix()).isEqualTo(Bytes.copyFrom(new byte[] {}));

    HpkeParameters tinkParams = paramsBuilder.setVariant(HpkeParameters.Variant.TINK).build();
    HpkePublicKey tinkPublicKey =
        HpkePublicKey.create(tinkParams, publicKeyBytes, /* idRequirement= */ 0x02030405);
    assertThat(tinkPublicKey.getIdRequirementOrNull()).isEqualTo(0x02030405);
    assertThat(tinkPublicKey.getOutputPrefix())
        .isEqualTo(Bytes.copyFrom(new byte[] {0x01, 0x02, 0x03, 0x04, 0x05}));

    HpkeParameters crunchyParams = paramsBuilder.setVariant(HpkeParameters.Variant.CRUNCHY).build();
    HpkePublicKey crunchyPublicKey =
        HpkePublicKey.create(crunchyParams, publicKeyBytes, /* idRequirement= */ 0x01020304);
    assertThat(crunchyPublicKey.getIdRequirementOrNull()).isEqualTo(0x01020304);
    assertThat(crunchyPublicKey.getOutputPrefix())
        .isEqualTo(Bytes.copyFrom(new byte[] {0x00, 0x01, 0x02, 0x03, 0x04}));
  }
Copied from {@link EllipticCurves#pointEncode} to bypass point validation.
java_src/src/test/java/com/google/crypto/tink/hybrid/HpkePublicKeyTest.java