예제 #1
0
        public static void GenerateKeys()
        {
            int          keySize   = 4096;
            var          keys      = EncryptorRSA.GenerateKeys(keySize);
            StreamWriter publicKey = new StreamWriter("publickey");

            publicKey.Write(keys.PublicKey);
            StreamWriter privateKey = new StreamWriter("privatekey");

            privateKey.Write(keys.PrivateKey);
            publicKey.Close();
            privateKey.Close();
        }
예제 #2
0
        public async Task RequestPublicKey()
        {
            var keyPair = EncryptorRSA.GenerateKeys(KeySize);

            if (KeyPairs.TryAdd(Context.ConnectionId, keyPair))
            {
                Console.WriteLine($"Generated new key pair for client with ConnectionId '{Context.ConnectionId}:" +
                                  $"\n\tPublic key: {keyPair.PublicKey}" +
                                  $"\n\tPrivate key: {keyPair.PrivateKey}");

                await Clients.Caller.SendAsync("PublicKey", keyPair.PublicKey);
            }
        }
예제 #3
0
파일: Program.cs 프로젝트: khanhlive/NDK
        static void Main(string[] args)
        {
            EncryptorRSAKeys key   = EncryptorRSA.GenerateKeys(2048);
            string           input = "";

            input = Console.ReadLine();
            string str = EncryptorRSA.EncryptText(input, key.PublicKey);

            Console.WriteLine("encrypt: " + str);
            Console.WriteLine("decrypt: " + EncryptorRSA.DecryptText(str, key.PrivateKey));
            Console.WriteLine(EncryptorRSA.GetMaxDataLength(16384));
            Console.ReadKey();
        }
예제 #4
0
        private static async Task RegenerateKeys()
        {
            while (true)
            {
                await Task.Delay(TimeSpan.FromMinutes(30));

                foreach (var keyValue in KeyPairs)
                {
                    var newPair = EncryptorRSA.GenerateKeys(KeySize);

                    keyValue.Value.PublicKey  = newPair.PublicKey;
                    keyValue.Value.PrivateKey = newPair.PrivateKey;

                    Console.WriteLine($"Generated new key pair for client with ConnectionId '{keyValue.Key}:" +
                                      $"\n\tPublic key: {keyValue.Value.PublicKey}" +
                                      $"\n\tPrivate key: {keyValue.Value.PrivateKey}");

                    await CallerClients.Caller.SendAsync("PublicKey", keyValue.Value.PublicKey);
                }
            }
        }