Created
April 8, 2019 20:51
-
-
Save AArnott/b4038ef7c6f5a001f1f62785f2faba74 to your computer and use it in GitHub Desktop.
Securely generates new PATs. Useful for a service that wants to issue PATs to users.
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
using System; | |
using System.Security.Cryptography; | |
public static class SecurityUtilities | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine(GeneratePat()); | |
Console.WriteLine(GeneratePat()); | |
Console.WriteLine(GeneratePat()); | |
} | |
public static string GeneratePat() | |
{ | |
const int bitStrength = 256; | |
Span<byte> randomData = stackalloc byte[bitStrength / 8]; | |
RandomNumberGenerator.Fill(randomData); | |
string pat = Convert.ToBase64String(randomData).Replace('+', '-').Replace('/', '_').TrimEnd('='); | |
return pat; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment