Exemplo n.º 1
0
        public void Test()
        {
            Random rand             = new Random();
            AsymmetricEncryption ae = new AsymmetricEncryption();

            for (int i = 0; i < 100; i++)
            {
                byte[] data = new byte[10000];
                rand.NextBytes(data);
                string text       = data.ToBase64String();
                string ciphertext = ae.EncryptToString(text);
                string plaintext  = ae.DecryptToString(ciphertext);
                Assert.AreEqual(text, plaintext);
            }
        }
Exemplo n.º 2
0
        public void DecryptWithoutPrivateKeyTest()
        {
            var encryption = new AsymmetricEncryption(_publicKey, null);

            Assert.Throws(typeof(CryptographicException), () => { encryption.DecryptToString(encryption.Encrypt("aw3lrifos83fusoi3fjsofisjfo")); });
        }
Exemplo n.º 3
0
        public void EncryptionStringEqualsTest()
        {
            var encryption = new AsymmetricEncryption(_publicKey, _privateKey);

            Assert.AreEqual("aw3lrifos83fusoi3fjsofisjfo", encryption.DecryptToString(encryption.Encrypt("aw3lrifos83fusoi3fjsofisjfo")));
        }