@Theory
  public void useAesCmacParametersAndAesCmacKey() throws Exception {
    AesCmacParameters parameters =
        AesCmacParameters.builder()
            .setKeySizeBytes(32)
            .setTagSizeBytes(13)
            .setVariant(AesCmacParameters.Variant.LEGACY)
            .build();
    KeysetHandle handle =
        KeysetHandle.newBuilder()
            .addEntry(
                KeysetHandle.generateEntryFromParameters(parameters).withFixedId(123).makePrimary())
            .build();

    AesCmacKey aesCmacKey = (AesCmacKey) handle.getAt(0).getKey();
    assertThat(aesCmacKey.getParameters()).isEqualTo(parameters);
    assertThat(aesCmacKey.getIdRequirementOrNull()).isEqualTo(123);
    SecretBytes secretBytes = aesCmacKey.getAesKey();
    assertThat(secretBytes.size()).isEqualTo(32);

    Mac mac = handle.getPrimitive(Mac.class);
    byte[] data = "data".getBytes(UTF_8);
    byte[] tag = mac.computeMac(data);
    mac.verifyMac(tag, data);
  }
Unit tests for the Mac package. Uses only the public API.
java_src/src/test/java/com/google/crypto/tink/mac/MacTest.java