using System.Security.Cryptography; using System.Text; namespace MareSynchronosShared.Utils; public static class StringUtils { public static string GenerateRandomString(int length, string? allowableChars = null) { if (string.IsNullOrEmpty(allowableChars)) allowableChars = @"ABCDEFGHJKLMNPQRSTUVWXYZ0123456789"; // Generate random data var rnd = RandomNumberGenerator.GetBytes(length); // Generate the output string var allowable = allowableChars.ToCharArray(); var l = allowable.Length; var chars = new char[length]; for (var i = 0; i < length; i++) chars[i] = allowable[rnd[i] % l]; return new string(chars); } public static string Sha256String(string input) { using var sha256 = SHA256.Create(); return BitConverter.ToString(sha256.ComputeHash(Encoding.UTF8.GetBytes(input))).Replace("-", "", StringComparison.OrdinalIgnoreCase); } }