Пример #1
0
        public void TestRSACipher()
        {
            FolaighKeyStore keyStore = new FolaighKeyStore(KEYSTORE, "bird8top".ToCharArray());
            RSACipher       cipher   = new RSACipher(
                keyStore,
                "countyKey",
                false);

            string cleartext = "This is some cleartext to encrypt with RSA.";

            byte[] encryptedText = cipher.encrypt(UTF8Encoding.UTF8.GetBytes(cleartext));
            Assert.IsNotNull(encryptedText);
            Assert.IsTrue(encryptedText.Length >= cleartext.Length);

            cipher = new RSACipher(
                keyStore,
                "countyKey",
                true);
            byte[] decryptedBytes = cipher.decrypt(encryptedText);
            Assert.IsNotNull(decryptedBytes);
            Assert.IsTrue(decryptedBytes.Length >= cleartext.Length);
            string decryptedText = UTF8Encoding.UTF8.GetString(decryptedBytes);

            Assert.AreEqual(cleartext, decryptedText);
        }