Skip to content
Advertisement

Secure random numbers in javascript?

How do I generate cryptographically secure random numbers in javascript?

Advertisement

Answer

You can for instance use mouse movement as seed for random numbers, read out time and mouse position whenever the onmousemove event happens, feed that data to a whitening function and you will have some first class random at hand. Though do make sure that user has moved the mouse sufficiently before you use the data.

Edit: I have myself played a bit with the concept by making a password generator, I wouldn’t guarantee that my whitening function is flawless, but being constantly reseeded I’m pretty sure that it’s plenty for the job: ebusiness.hopto.org/generator.htm

Edit2: It now sort of works with smartphones, but only by disabling touch functionality while the entropy is gathered. Android won’t work properly any other way.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement