JavaScript Key Generator
In the past, encryption and decryption had to be done through native code libraries, such as with Bouncy Castle and OpenSSL. With the increasing processing power of Web browsers, it is now possible to use encryption using JavaScript, which thus provides client-side processing of data. This Web page uses Javascript encryption, and generates a random 256-bit text key or a hex version. The 256-bit key is generated by generating 60 random numbers (from 0-25), and converting these to an ASCII character:
It uses the JavaScript from https://www.fourmilab.ch. First we generate a random seed:
var seed = keyFromEntropy();
and then generate the random numbers from the seed with (prng is Pseudo Random Number Generator):
var prng = new AESprng(seed);
Next we generate 60 random integers, from 0 to 25, and then convert into ASCII, where 'A' is 0, 'B' is 1, and so on:
k += String.fromCharCode(charA + prng.nextInt(25));
The full code is:
function Generate_key() { var i, j, k = ""; var i, j, k = ""; addEntropyTime(); var seed = keyFromEntropy(); var prng = new AESprng(seed); if (document.key.keytype[0].checked) { // Text key var charA = ("A").charCodeAt(0); for (i = 0; i < 12; i++) { if (i > 0) { k += "-"; } for (j = 0; j < 5; j++) { k += String.fromCharCode(charA + prng.nextInt(25)); } } } else { // Hexadecimal key var hexDigits = "0123456789ABCDEF"; for (i = 0; i < 64; i++) { k += hexDigits.charAt(prng.nextInt(15)); } } document.key.text.value = k; delete prng; }