using System; using System.Security.Cryptography; using System.Text; namespace ArchestrAServices.Common; public class ASBConfigurationInformation { private const string DefaultCryptoGenerator = "22"; private const int DefaultKeySize = 256; private const string DefaultPrime768 = "1552518092300708935130918131258481755631334049434514313202351194902966239949102107258669453876591642442910007680288864229150803718918046342632727613031282983744380820890196288509170691316593175367469551763119843371637221007210577919"; private const string DefaultHashAlgorithm = "None"; private const int DefaultPasswordIterations = 1; private const string DefaultSaltValue = "s@1tValue"; private const string DefaultInitializationVector = "ba172e9941be138b"; public string SolutionName { get; set; } public string Generator { get; set; } public string Prime { get; set; } public string HashAlgorithm { get; set; } public string InitializationVector { get; set; } public string SaltValue { get; set; } public int PasswordDerivationIterations { get; set; } public int KeySize { get; set; } public string EncryptedSharedSecret { get; set; } public string EncryptedCertificate { get; set; } public string IsDefault { get; set; } public string SRNodeName { get; set; } public string PrimaryGlobalDiscovery { get; set; } public string SecondaryGlobalDiscovery { get; set; } public string PrimaryUniversalDiscovery { get; set; } public string SecondaryUniversalDiscovery { get; set; } public ASBConfigurationInformation() { Generator = "22"; KeySize = 256; Prime = "1552518092300708935130918131258481755631334049434514313202351194902966239949102107258669453876591642442910007680288864229150803718918046342632727613031282983744380820890196288509170691316593175367469551763119843371637221007210577919"; HashAlgorithm = "None"; PasswordDerivationIterations = 1; SaltValue = "s@1tValue"; InitializationVector = "ba172e9941be138b"; } public static string GetNewSharedSecret(int length) { if (length < 1) { throw new ArgumentOutOfRangeException("length"); } StringBuilder stringBuilder = new StringBuilder(length); RNGCryptoServiceProvider rNGCryptoServiceProvider = new RNGCryptoServiceProvider(); try { char[] array = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890".ToCharArray(); byte[] array2 = new byte[1]; for (int i = 0; i < length; i++) { do { rNGCryptoServiceProvider.GetBytes(array2); } while (!IsFairRandomNumber(array2[0], array.Length)); stringBuilder.Append(array[array2[0] % array.Length]); } } finally { rNGCryptoServiceProvider.Dispose(); } return stringBuilder.ToString(); } private static bool IsFairRandomNumber(byte randomNumber, int numChars) { int num = 255 / numChars; return randomNumber < numChars * num; } }