ENCRYPTION_KEY, docs

This commit is contained in:
jokob-sk
2024-12-31 10:14:01 +11:00
parent 8ac4112ab9
commit e52601e062
31 changed files with 183 additions and 9 deletions

View File

@@ -455,6 +455,8 @@ function utf8ToBase64(str) {
// General utilities
// -----------------------------------------------------------------------------
// check if JSON object
function isJsonObject(value) {
return typeof value === 'object' && value !== null && !Array.isArray(value);

View File

@@ -1245,7 +1245,7 @@ function collectTableData(tableSelector) {
rowData[index] = { [input.attr("my-originalsetkey")] : input.prop('checked') };
} else {
// Generic sync for other inputs (text, select, textarea)
rowData[index] = { [input.attr("my-originalsetkey")] : input.val() };
rowData[index] = { [input.attr("my-originalsetkey")] : input.val().replace(/'/g, "").replace(/"/g, "") };
}
} else {
// Handle plain text

View File

@@ -97,6 +97,37 @@ function generateApiToken(elem, length) {
}
}
// ----------------------------------------------
// Generate a random N-byte hexadecimal key
function getRandomBytes(elem, length) {
// Retrieve and parse custom parameters from the element
let params = $(elem).attr("my-customparams")?.split(',').map(param => param.trim());
if (params && params.length >= 1) {
var targetElementID = params[0]; // Get the target element's ID
}
let targetElement = $('#' + targetElementID);
// Generate random bytes
const array = new Uint8Array(length);
window.crypto.getRandomValues(array);
// Convert bytes to hexadecimal string
let hexString = Array.from(array, byte =>
byte.toString(16).padStart(2, '0')
).join('');
// Format hexadecimal string with hyphens
let formattedHex = hexString.match(/.{1,2}/g).join('-');
console.log(formattedHex);
// console.log($(`#${targetInput}`).val());
// Set the formatted key value to the input field
targetElement.val(formattedHex);
}