示例#1
0
        public Principal(string name, int generator, int modulus)
        {
            Console.WriteLine($"Creating principal {name}...");
            Name      = name;
            Generator = generator;
            Modulus   = modulus;

            _secret       = PrimeGenerator.GetPrime();
            SecretMessage = SquareAndMultiply.Calculate(Generator, _secret, Modulus);

            Console.WriteLine($"{Name} has selected a secret: {_secret}");
            Console.WriteLine($"{Name} calculated its secret message ({Generator}^{_secret}) mod {modulus}: {SecretMessage}");

            rsa         = new RSACryptoServiceProvider(2048);
            _publicKey  = rsa.ExportParameters(false);
            _privateKey = rsa.ExportParameters(true);

            Console.WriteLine($"{Name} created 2048 bit RSA public and private keys");

            RSAPublicKeyStore.AddPublicKey(Name, _publicKey);

            _secretMessages       = new Dictionary <string, int>();
            _symmetricKeys        = new Dictionary <string, string>();
            _authorizedPrincipals = new HashSet <string>();

            Console.WriteLine($"Principal {Name} has been created successfully.\r\n");
        }