Esempio n. 1
0
        public void Bob()
        {
            var aliceKeyPair = new PublicKeyGenerator().MakeKeyPair();
            var bobKeyPair   = new PublicKeyGenerator().MakeKeyPair();
            var crypto       = new RsaCryptographyService();

            var message = "ch";

            //message from bob to alice - encrypt with alice public key - sign with bob's private key
            var keyPair = new KeyPair(aliceKeyPair.Public, bobKeyPair.Private);

            var cipherText = crypto.SignAndEncrypt(keyPair, message);

            Console.WriteLine(cipherText);

            //message received - decrypt with alice private - verify with bob's public key
            var k2    = new KeyPair(bobKeyPair.Public, aliceKeyPair.Private);
            var clear = crypto.DecryptAndAuthenticate(k2, cipherText);

            Console.WriteLine(clear);
        }
Esempio n. 2
0
        public void Bob()
        {
            var aliceKeyPair = new PublicKeyGenerator().MakeKeyPair();
            var bobKeyPair = new PublicKeyGenerator().MakeKeyPair();
            var crypto = new RsaCryptographyService();

            var message = "ch";

            //message from bob to alice - encrypt with alice public key - sign with bob's private key
            var keyPair = new KeyPair(aliceKeyPair.Public, bobKeyPair.Private);

            var cipherText = crypto.SignAndEncrypt(keyPair, message);
            Console.WriteLine(cipherText);

            //message received - decrypt with alice private - verify with bob's public key
            var k2 = new KeyPair(bobKeyPair.Public, aliceKeyPair.Private);
            var clear = crypto.DecryptAndAuthenticate(k2, cipherText);
            Console.WriteLine(clear);
        }