Ejemplo n.º 1
0
        public void SetUp()
        {
            var pkg = new PublicKeyGenerator();
            _alice = pkg.MakeKeyPair();
            _bob = pkg.MakeKeyPair();

            //encrypting from bob -> alice
            _forEncryption = new KeyPair(_alice.Public, _bob.Private);
            _forDecryption = new KeyPair(_bob.Public, _alice.Private);
        }
Ejemplo 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);
        }
Ejemplo n.º 3
0
        public RsaCryptographyService()
        {
            var publicKeyGenerator = new PublicKeyGenerator();

            _rsaCryptoServiceProvider = publicKeyGenerator.GetRsa();
        }
Ejemplo n.º 4
0
 public RsaCryptographyService()
 {
     var publicKeyGenerator = new PublicKeyGenerator();
     _rsaCryptoServiceProvider = publicKeyGenerator.GetRsa();
 }
Ejemplo n.º 5
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);
        }