Created
September 11, 2018 15:30
-
-
Save ti-ka/72350c4cd10306cd2c7eee57442a6565 to your computer and use it in GitHub Desktop.
Generate Token C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var bytes = new byte[40]; // byte size | |
using (var crypto = new RNGCryptoServiceProvider()) | |
crypto.GetBytes(bytes); | |
var base64 = Convert.ToBase64String(bytes); | |
Console.WriteLine(base64); | |
// Prepend with a Guid: | |
var result = Guid.NewGuid().ToString("N") + Convert.ToBase64String(bytes); | |
Console.WriteLine(result); | |
// Alphanumeric string: | |
result = Regex.Replace(result,"[^A-Za-z0-9]",""); | |
Console.WriteLine(result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment