コード例 #1
0
        static void Main(string[] args)
        {
            //JustRSA();
            var agent1 = new AgentSafeFromNSA();
            var agent2 = new AgentSafeFromNSA();

            var secret  = Utility.GetSecret();
            var message = Utility.ConvertBytesToString64(secret);

            var rsaRes = agent1.EncryptAndSignMessageRSA(message, agent2.RSAParametersPublic);

            Console.WriteLine("RSA result:");
            Console.WriteLine($"Encrypted data: {rsaRes.Encrypted}");
            Console.WriteLine($"Signed: {rsaRes.Signed}");

            var decrypted = agent2.DecryptAdnVerifySignedMessageRSA(rsaRes.Encrypted, rsaRes.Signed, agent1.RSAParametersPublic);

            Console.WriteLine($"Decryted: {decrypted}");

            var returnMessage = "I'll send an SOS to the world";
            var hmacHash      = agent2.SignMessageHMAC(returnMessage, Utility.ConvertFromString64ToBytes(decrypted));

            Console.WriteLine($"HMACH HASH {hmacHash}");

            var verification = agent1.VerifyMessageHMAC(returnMessage, Utility.ConvertFromString64ToBytes(hmacHash), secret);

            Console.WriteLine($"Verified? {verification}");
            Console.WriteLine($"Message {returnMessage}");
            Console.ReadKey();
        }
コード例 #2
0
        private static void JustRSA()
        {
            var agent1 = new AgentSafeFromNSA();
            var agent2 = new AgentSafeFromNSA();

            var message = "in the bottle";

            var rsaRes = agent1.EncryptAndSignMessageRSA(message, agent2.RSAParametersPublic);

            Console.WriteLine("RSA result:");
            Console.WriteLine($"Encrypted data: {rsaRes.Encrypted}");
            Console.WriteLine($"Signed: {rsaRes.Signed}");

            var decrypted = agent2.DecryptAdnVerifySignedMessageRSA(rsaRes.Encrypted, rsaRes.Signed, agent1.RSAParametersPublic);

            Console.WriteLine($"Decryted: {decrypted}");
        }