dimanche 30 juillet 2017

Random string generation that's URL friendly and isn't hex

Here's the code I'm using to generate some small random keys but I want to include the rest of the English alphabet not just A-F that gets generated using hex.

I've tried a few encodings but they all include many more characters than I want and are not url friendly.

The below works fine I am just curious on how to solve this.

byte[] bytes = new byte[4];
using (var rng = RandomNumberGenerator.Create())
{
    rng.GetBytes(bytes);
}
string key = string.Join("", bytes.Select(b => b.ToString("X2")));




Aucun commentaire:

Enregistrer un commentaire