public static byte[] toByteArray(KeyTemplate keyTemplate) throws GeneralSecurityException {
    return toProto(keyTemplate).toByteArray();
  }
KeyTemplateProtoConverter converts KeyTemplate to and from the binary proto format.
java_src/src/main/java/com/google/crypto/tink/internal/KeyTemplateProtoConverter.java