Last active
August 29, 2015 14:25
-
-
Save codenamejason/40d84694fc0972a84b12 to your computer and use it in GitHub Desktop.
RandomOAuthStateGen
This file contains hidden or 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
| private static class RandomOAuthStateGenerator | |
| { | |
| private static RandomNumberGenerator _random = new RNGCryptoServiceProvider(); | |
| public static string Generate(int strengthInBits) | |
| { | |
| const int bitsPerByte = 8; | |
| if (strengthInBits % bitsPerByte != 0) | |
| { | |
| throw new ArgumentException("strengthInBits must be evenly divisible by 8.", "strengthInBits"); | |
| } | |
| int strengthInBytes = strengthInBits / bitsPerByte; | |
| byte[] data = new byte[strengthInBytes]; | |
| _random.GetBytes(data); | |
| return HttpServerUtility.UrlTokenEncode(data); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment