Ejemplo n.º 1
0
        public void RSASimpleEncryptDecrypt()
        {
            var rsa = new SimpleRSA(11, 13);

            Assert.AreEqual(rsa.Modulo, 143u);
            Assert.AreEqual(rsa.PublicKey, 7u);
            Assert.AreEqual(rsa.PrivateKey, 103u);
            Assert.AreEqual(rsa.Encrypt(5), 47u);
            Assert.AreEqual(rsa.Decrypt(47), 5u);
        }
Ejemplo n.º 2
0
        private void GenNewKeys(object sender, RoutedEventArgs e)
        {
            string pubKey;
            string priKey;

            SimpleRSA.GenerateBase64RSAKeys(keysize[cbxKeys.SelectedIndex], out priKey, out pubKey);
            var cryptoServiceProvider = new System.Security.Cryptography.RSACryptoServiceProvider(keysize[cbxKeys.SelectedIndex]);

            publicKey.Text  = cryptoServiceProvider.ExportPublicKey();
            privateKey.Text = cryptoServiceProvider.ExportPrivateKey();
        }
Ejemplo n.º 3
0
        public void RSALongMessageEncryption()
        {
            var rsa = new SimpleRSA(3, 11);

            Assert.AreEqual(rsa.Modulo, 33u);
            Assert.AreEqual(rsa.PublicKey, 3u);
            Assert.AreEqual(rsa.PrivateKey, 7u);
            var message = new List <uint> {
                1, 5, 31, 14, 8
            };
            var expected = new List <uint>();

            foreach (var value in message)
            {
                expected.Add(NumericUtilities.SolveModulo(value, rsa.PublicKey, rsa.Modulo));
            }
            var encrypted = rsa.Encrypt(message);

            Assert.IsTrue(expected.SequenceEqual(encrypted));
            Assert.IsTrue(message.SequenceEqual(rsa.Decrypt(encrypted)));
        }