fortuna prng code example
Example: fortuna based rng js
var os = require('os');
if (os.platform() == 'win32') {
if (os.arch() == 'ia32') {
var chilkat = require('@chilkat/ck-node11-win-ia32');
} else {
var chilkat = require('@chilkat/ck-node11-win64');
}
} else if (os.platform() == 'linux') {
if (os.arch() == 'arm') {
var chilkat = require('@chilkat/ck-node11-arm');
} else if (os.arch() == 'x86') {
var chilkat = require('@chilkat/ck-node11-linux32');
} else {
var chilkat = require('@chilkat/ck-node11-linux64');
}
} else if (os.platform() == 'darwin') {
var chilkat = require('@chilkat/ck-node11-macosx');
}
function chilkatExample() {
var chilkatGlob = new chilkat.Global();
var success = chilkatGlob.UnlockBundle("Anything for 30-day trial.");
if (success !== true) {
console.log(chilkatGlob.LastErrorText);
return;
}
var fortuna = new chilkat.Prng();
var strEntropy = fortuna.GetEntropy(32,"hex");
if (fortuna.LastMethodSuccess !== true) {
console.log(fortuna.LastErrorText);
return;
}
success = fortuna.AddEntropy(strEntropy,"hex");
if (success !== true) {
console.log(fortuna.LastErrorText);
return;
}
var strRandHex = fortuna.GenRandom(16,"hex");
var strRandBase64 = fortuna.GenRandom(22,"base64");
var strRandBase58 = fortuna.GenRandom(32,"base58");
console.log("hex random bytes: " + strRandHex);
console.log("base64 random bytes: " + strRandBase64);
console.log("base58 random bytes: " + strRandBase58);
}
chilkatExample();