@AccessesPartialKey
  @SuppressWarnings("UnusedException")
  private static PrfBasedKeyDerivationKey parseKey(
      ProtoKeySerialization serialization, @Nullable SecretKeyAccess access)
      throws GeneralSecurityException {
    if (!serialization.getTypeUrl().equals(TYPE_URL)) {
      throw new IllegalArgumentException(
          "Wrong type URL in call to PrfBasedKeyDerivationKey.parseKey");
    }
    try {
      PrfBasedDeriverKey protoKey =
          PrfBasedDeriverKey.parseFrom(
              serialization.getValue(), ExtensionRegistryLite.getEmptyRegistry());
      ProtoKeySerialization prfKeySerialization =
          ProtoKeySerialization.create(
              protoKey.getPrfKey().getTypeUrl(),
              protoKey.getPrfKey().getValue(),
              protoKey.getPrfKey().getKeyMaterialType(),
              OutputPrefixType.RAW,
              /* idRequirement= */ null);
      Key prfKeyUncast =
          MutableSerializationRegistry.globalInstance().parseKey(prfKeySerialization, access);
      if (!(prfKeyUncast instanceof PrfKey)) {
        throw new GeneralSecurityException("Non-PRF key stored in the field prf_key");
      }
      PrfKey prfKey = (PrfKey) prfKeyUncast;
      ProtoParametersSerialization derivedKeyParametersSerialization =
          ProtoParametersSerialization.checkedCreate(protoKey.getParams().getDerivedKeyTemplate());
      Parameters derivedKeyParameters =
          MutableSerializationRegistry.globalInstance()
              .parseParameters(derivedKeyParametersSerialization);
      PrfBasedKeyDerivationParameters parameters =
          PrfBasedKeyDerivationParameters.builder()
              .setDerivedKeyParameters(derivedKeyParameters)
              .setPrfParameters(prfKey.getParameters())
              .build();

      if (serialization.getOutputPrefixType()
          != derivedKeyParametersSerialization.getKeyTemplate().getOutputPrefixType()) {
        throw new GeneralSecurityException(
            "Output-Prefix mismatch in parameters while parsing PrfBasedKeyDerivationKey with"
                + " parameters "
                + parameters);
      }

      return PrfBasedKeyDerivationKey.create(
          parameters, prfKey, serialization.getIdRequirementOrNull());
    } catch (InvalidProtocolBufferException e) {
      // Suppressing Exception to prevent leakage of key material
      throw new GeneralSecurityException("Parsing HmacKey failed");
    }
  }
Methods to serialize and parse {@link PrfBasedKeyDerivationKey} and {@link
PrfBasedKeyDerivationParameters} objects.
java_src/src/main/java/com/google/crypto/tink/keyderivation/internal/PrfBasedKeyDerivationKeyProtoSerialization.java