public static string GenerateMiniKey(CharacterPool type = CharacterPool.AlphanumericMixedCase) { RandomNumberGenerator random = System.Security.Cryptography.RandomNumberGenerator.Create(); var pool = Encoders.GetCharacterPool(type); while (true) { var bytes = new byte[29]; random.GetNonZeroBytes(bytes); var minikey = "S" + new String(bytes.Select <byte, char>(x => pool[x % pool.Length]).ToArray()); try { ValidateMiniKey(minikey); return(minikey); } catch (Exception e) { if (e.Message != "Failed to pass typo check") { var aa = minikey.Length; Console.WriteLine(aa); } } } }
static void CheckBase58(string key) { var pool = Encoders.GetCharacterPool(); foreach (char c in key) { if (!pool.Contains(c)) { throw new System.ArgumentException("Key cannot contain the '" + c + "' character"); } } }