diff options
| author | ivar <i@oiee.no> | 2025-10-19 23:41:23 +0200 |
|---|---|---|
| committer | ivar <i@oiee.no> | 2025-10-19 23:41:23 +0200 |
| commit | 3f4c0720e1e3421431e7baa20882a4a4512a7fab (patch) | |
| tree | 734ca81d7d0841d8863e3f523ebba14c282dc681 /src/Utilities/Cryptography.cs | |
| download | fagprove-master.tar.xz fagprove-master.zip | |
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 |
