Is there anything similar to https://developer.mozilla.org/en/javascript_crypto for IE or webkit browsers?
I just need to generate cryptographically secure pseudo-random numbers, but I don't want to have to include a large 3rd party js library.
Is there anything similar to https://developer.mozilla.org/en/javascript_crypto for IE or webkit browsers?
I just need to generate cryptographically secure pseudo-random numbers, but I don't want to have to include a large 3rd party js library.
you should read into a buffer instead a directly into a string, as the above code will be UTF-8 encoded (why you have so many \0xFFFD bytes)
This is a fairly small SHA1 module that could be seeded with Date.now + some salt n pepper to provide a fairly random string. Strip out the alphas and keep calling until you have enough numbers for your needs.
http://www.movable-type.co.uk/scripts/sha1.html
Definitely hacky - so perhaps an ajax call to a webservice would suffice?
I second the webservice idea and offer this suggestion: random.org, a truly random numbers generator.
I noticed "crypto" in the Firefox 3 global scope, then found this reference.
Unfortunately, when I try crypto.random(8)
in the JavaScript Error Console, it throws a NotImplemented
error. I'd like to see this function made standard.
On node.js running on osx/linux I recommend this:
node> var urandom = fs.openSync('/dev/urandom', 'r');
node> fs.readSync(urandom, 8);
[ '.\ufffd\u000f\ufffdK!L\ufffd', 8 ]
I believe a synchronous read is ok, because /dev/urandom
will always be non-blocking and doesn't rely on disk IO.