简单的JS密钥生成函数,按需自取

// 字典表
let DICT_EN_LOWER = "abcdefghijklmnopqrstuvwxyz";
let DICT_EN_UPPER = DICT_EN_LOWER.toUpperCase();
let DICT_NUM = "01234567890";
let DICT_16_UPPER = "012345679ABCDEF";
let DICT_16_LOWER = DICT_EN_LOWER.toUpperCase();

/**
 * 创建秘钥
 * @param length
 * @param dict
 * @returns {string}
 */
function createKey(length = 32, dict = "") {
    if (!dict) dict = [...new Set((DICT_EN_LOWER + DICT_EN_UPPER + DICT_NUM + DICT_16_UPPER + DICT_16_LOWER).split("").sort())];
    let str = "";
    for (let i = 0; i < length; i++) {
        str += dict[Math.floor(Math.random() * dict.length)];
    }
    return str;
}

// 控制台打印
console.table({
    "32位秘钥": createKey(),
    "16进制秘钥16位": createKey(16, DICT_16_LOWER + DICT_16_UPPER)
})