2

I want to to generate a secure, randomised string, in JavaScript. There isn't much around about security in JavaScript, because it is usually used on the client-side – in this case, I'm using it on the server-side with Node.js.

I could create a for loop that adds a random character to a string each time around – but are there any libraries, functions, or anything else that I can install with npm, that uses SSL security-like code, encryption or the like?


Also, please answer with a variety of options – this will be the most useful.


Stackoverflow seems to think that there is another answer that is similar to this one. But I disagree. This question asks:

Is there a more elegant way?

– to an existing piece of code. My question is more broard, and could be helpful to people that have no previous knoledge of random string generation in JavaScript. Also, this question could attract a wider range of answers, giving many different methods, that can be compared.

Community
  • 1
  • 1
Luke
  • 2,038
  • 3
  • 22
  • 46
  • 2
    Possible duplicate of [Secure random token in Node.js](http://stackoverflow.com/questions/8855687/secure-random-token-in-node-js) – Alexander O'Mara Feb 07 '16 at 08:31
  • @Mirabilis You could argue that the answers to that question are good enough as answers to your question. In that case your question is likely to get closed (which doesn't mean that the question is bad in anyway, and it may not even get deleted because it may be a good lead to the other question / answers). Is there anything in those answers that make them insufficient to answer *your question*? (side note: you wrote "more broard") – Maarten Bodewes Feb 07 '16 at 14:52
  • WebCrypto should provide the services. But its in [jeopardy of not being standardized](https://lists.w3.org/Archives/Public/public-webcrypto/2016Jan/0001.html) due to lack of browser interest. Chrome is ready to abandon it. – jww Feb 07 '16 at 19:45
  • @MaartenBodewes, all the answers in that question use the `crypto` library – what if there is another library that will suit other situations better? We won't know if the question is closed. – Luke Feb 07 '16 at 21:10

1 Answers1

1

There is an npm module called secure-random-string that should do what you're looking for.

Peter G
  • 2,773
  • 3
  • 25
  • 35
  • There should be enough information in your answer for it to be useful to future visitors even if the link fails. – BSMP Feb 07 '16 at 08:33