I need some viable sources for entropy to seed a CSPRNG. So far, I have:

  • JS Events
  • Web Crypto API
  • performance.now()
  • Timing for xmlHTTPRequests
  • etc.

Are there any other viable/secure entropy sources that I can use/access in JavaScript?

  • 1
    Why not just use the tools built-in to the browser which are already cryptographically secure? Doing this well is very difficult. This is probably one of those cases where it is better to leave it up to the "professionals". To be clear, I don't say that to question your skills at all. Almost no one is qualified enough to generate good crypto by themselves (I'm certainly not). It's only through intense and long-lasting public scrutiny that all the "bugs" get ironed out. Commented Aug 27, 2019 at 21:17
  • I do need a lot of entropy because the numbers I need must be truly random, but if I use a webservice, that is prone to a MITM even with TLS. So a solution is to generate as much local entropy as possible. Commented Aug 27, 2019 at 21:20
  • 1
    The built-in tools in the browsers that Conor suggested are local to the client. You're specifically looking for Crypto.getRandomValues().
    – Ghedipunk
    Commented Aug 27, 2019 at 21:49
  • 1
    I wrote a javascript library a while back to collect unpredictable values from hardware sources available to web applications. It can use a microphone, cam, motion sensors, and differential clocks to collect entropy. TBH, it's rusted a bit since, but the code might give you some ideas. You might also see the stamp() function nadachat uses, which collects dynamic inputs like performance.timing that while not truely random, are somewhat unpredictable.
    – dandavis
    Commented Aug 28, 2019 at 3:54

1 Answer 1


Fortunately, you don't have to choose. The xor function has the property that if you xor multiple independent source of entropy streams, the resulting output stream is going to have at least the entropy of the stronger source.

Web Crypto CSPRNG (Crypto.getRandomValues()) is all you will need to generate crypto keys. But if you for some reason don't trust the smart people who wrote your browser, you can just xor together the output of Web Crypto with other entropy sources of your choice, say request some random bits from random.org, the URL of some random advertising network, etc. Just mix them all together, it won't harm the entropy level.

  • This is actually the first good answer I've gotten to questions such as these. Thanks. Commented Aug 28, 2019 at 3:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .