--- /dev/null
+#!/usr/bin/env node
+'use strict';
+
+/**
+ * Simple script to create a secret key for mysterybox configuration.
+ */
+
+const { randomBytes } = require('node:crypto');
+
+/**
+ * Get the value following a command line option.
+ * Removes the option and its value from the command line arguments.
+ * @param {string} option e.g. '--bytes'
+ * @returns {string} value following the option
+ */
+function cliGetOption(option) {
+ let value;
+ while (process.argv.includes(option)) {
+ const optionIndex = process.argv.indexOf(option);
+ value = process.argv.splice(optionIndex, 2)[1];
+ if (value === undefined) {
+ throw new Error(`Missing value for option: ${option}`);
+ }
+ }
+ return value;
+}
+
+const bytes = parseInt(cliGetOption('--bytes'), 10) || 64;
+const encoding = cliGetOption('--encoding') || 'base64url';
+
+randomBytes(bytes, (err, buf) => {
+ if (err) {
+ console.error(err);
+ throw err;
+ }
+ const secret = buf.toString(encoding);
+ console.log(`Buffer.from('${secret}', '${encoding}')`);
+});