public static void createKey(
      CommandType type,
      OutputStream outputStream,
      String outFormat,
      InputStream inputStream,
      String inFormat,
      String masterKeyUri,
      String credentialPath,
      Parameters parameters)
      throws GeneralSecurityException, IOException {
    KeysetHandle.Builder builder =
        KeysetHandle.newBuilder(
            getKeysetHandle(inputStream, inFormat, masterKeyUri, credentialPath));
    switch (type) {
      case ADD_KEY:
        builder.addEntry(KeysetHandle.generateEntryFromParameters(parameters).withRandomId());
        break;
      case ROTATE_KEYSET:
        builder.addEntry(
            KeysetHandle.generateEntryFromParameters(parameters).withRandomId().makePrimary());
        break;
      default:
        throw new GeneralSecurityException("invalid command");
    }

    writeKeyset(builder.build(), outputStream, outFormat, masterKeyUri, credentialPath);
  }
Creates and adds a new key to an existing keyset. The new key becomes the primary key if {@code
type} is {@link CommandType#ROTATE}.
tools/tinkey/src/main/java/com/google/crypto/tink/tinkey/TinkeyUtil.java