@Test
  public void createTemplateAndDeriveHmacKeyset_success() throws Exception {
    Parameters keyDerivationParameters =
        PrfBasedKeyDerivationParameters.builder()
            .setPrfParameters((PrfParameters) KeyTemplates.get("HKDF_SHA256").toParameters())
            .setDerivedKeyParameters(KeyTemplates.get("HMAC_SHA256_128BITTAG").toParameters())
            .build();

    KeysetHandle handle = KeysetHandle.generateNew(keyDerivationParameters);
    KeysetDeriver deriver = handle.getPrimitive(KeysetDeriver.class);

    KeysetHandle derivedHandle = deriver.deriveKeyset("salt".getBytes(UTF_8));

    // Use derived keyset, which should contain an HMAC key.
    Mac mac = derivedHandle.getPrimitive(Mac.class);
    byte[] data = "data".getBytes(UTF_8);
    byte[] tag = mac.computeMac(data);
    mac.verifyMac(tag, data);
  }
Unit tests for the Key Derivation package. Uses only the public API.
java_src/src/test/java/com/google/crypto/tink/keyderivation/KeyDerivationTest.java