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.
你应该读入缓冲区而不是直接读入字符串,因为上面的代码将是UTF-8编码的(为什么你有这么多的\\ 0xFFFD字节)
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.