I need to generate a random password that will be used in OpenPGP.js to encrypt something symmetrically. The user should never have to touch or see the password (everything happens behind the scenes). Thus, ideally the password would just be a number of random bytes. Unfortunately, OpenPGP.js does not support that (to my knowledge). It only supports strings as passwords.
So I need to generate a random password string. I want it to be as random as possible; excluding as few characters as possible.
How can I generate a secure random password string?
I currently have this:
String.fromCharCode.apply(null, crypto.getRandomValues(new Uint8Array(32)));
However, I'm a little worried that it might mess up UTF-16 surrogate pairs when certain random bytes appear, and that the password might get interpreted differently on other browsers depending on their Unicode implementation.
Is this solution safe to use across browsers?