Example #1
0
    public void Encrypt()
    {
        using (RSAKeyPair kp = new RSAKeyPair())
        {
            string data                = "Hello my name is Maitland";
            byte[] dataEncrypted       = kp.Encrypt(data, Encoding.UTF8);
            string dataConvertedToUTF8 = Encoding.UTF8.GetString(dataEncrypted);

            Assert.AreNotEqual(data, dataConvertedToUTF8);
        }
    }
Example #2
0
    public void Decrypt()
    {
        using (RSAKeyPair kp = new RSAKeyPair())
            using (RSAKeyPair kp2 = new RSAKeyPair())
            {
                string data = "Hello I am Maitland I make code";

                byte[] dataEncrypted = kp.Encrypt(data, Encoding.UTF8);
                string dataDecrypted = kp.Decrypt(dataEncrypted, Encoding.UTF8);

                Assert.AreEqual(data, dataDecrypted);
                Assert.ThrowsException <CryptographicException>(() =>
                {
                    kp2.Decrypt(dataEncrypted, Encoding.UTF8);
                });
            }
    }