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); }
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); }
public RsaCryptographyService() { var publicKeyGenerator = new PublicKeyGenerator(); _rsaCryptoServiceProvider = publicKeyGenerator.GetRsa(); }