diff options
Diffstat (limited to 'src/Utilities/Cryptography.cs')
| -rw-r--r-- | src/Utilities/Cryptography.cs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/Utilities/Cryptography.cs b/src/Utilities/Cryptography.cs new file mode 100644 index 0000000..cdf4984 --- /dev/null +++ b/src/Utilities/Cryptography.cs @@ -0,0 +1,26 @@ +using System.Security.Cryptography; +using System.Text; + +namespace IOL.Fagprove.Utilities +{ + public class Cryptography + { + public static string RandomString(int length = 12) + { + var chars = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray(); + var data = new byte[length]; + using (var crypto = new RNGCryptoServiceProvider()) + { + crypto.GetBytes(data); + } + + var result = new StringBuilder(length); + foreach (var b in data) + { + result.Append(chars[b % (chars.Length)]); + } + + return result.ToString(); + } + } +}
\ No newline at end of file |
