public static com.google.crypto.tink.proto.KeyTemplate toProto(KeyTemplate keyTemplate)
      throws GeneralSecurityException {
    Parameters parameters = keyTemplate.toParameters();
    if (parameters instanceof LegacyProtoParameters) {
      return ((LegacyProtoParameters) parameters).getSerialization().getKeyTemplate();
    }
    ProtoParametersSerialization s =
        MutableSerializationRegistry.globalInstance()
            .serializeParameters(parameters, ProtoParametersSerialization.class);
    return s.getKeyTemplate();
  }
KeyTemplateProtoConverter converts KeyTemplate to and from the binary proto format.
java_src/src/main/java/com/google/crypto/tink/internal/KeyTemplateProtoConverter.java