private static ProtoKeySerialization serializeKey(
      JwtHmacKey key, @Nullable SecretKeyAccess access) throws GeneralSecurityException {
    com.google.crypto.tink.proto.JwtHmacKey.Builder protoKeyBuilder =
        com.google.crypto.tink.proto.JwtHmacKey.newBuilder();
    protoKeyBuilder
        .setVersion(0)
        .setAlgorithm(toProtoAlgorithm(key.getParameters().getAlgorithm()))
        .setKeyValue(
            ByteString.copyFrom(
                key.getKeyBytes().toByteArray(SecretKeyAccess.requireAccess(access))));
    OutputPrefixType outputPrefixType = null;
    if (key.getParameters().getKidStrategy().equals(JwtHmacParameters.KidStrategy.CUSTOM)) {
      protoKeyBuilder.setCustomKid(CustomKid.newBuilder().setValue(key.getKid().get()));
      outputPrefixType = OutputPrefixType.RAW;
    }
    if (key.getParameters().getKidStrategy().equals(JwtHmacParameters.KidStrategy.IGNORED)) {
      outputPrefixType = OutputPrefixType.RAW;
    }
    if (key.getParameters()
        .getKidStrategy()
        .equals(JwtHmacParameters.KidStrategy.BASE64_ENCODED_KEY_ID)) {
      outputPrefixType = OutputPrefixType.TINK;
    }
    if (outputPrefixType == null) {
      throw new GeneralSecurityException(
          "Unknown KID Strategy in " + key.getParameters().getKidStrategy());
    }

    return ProtoKeySerialization.create(
        TYPE_URL,
        protoKeyBuilder.build().toByteString(),
        KeyMaterialType.SYMMETRIC,
        outputPrefixType,
        key.getIdRequirementOrNull());
  }
Methods to serialize and parse {@link JwtHmacKey} objects and {@link JwtHmacParameters} objects.
java_src/src/main/java/com/google/crypto/tink/jwt/JwtHmacProtoSerialization.java