コード例 #1
0
        public void ByteStringEncryptor()
        {
            KeyPair kp = new KeyPair();
            string publicKey = kp.PublicKey;

            string textToEncrypt = "Colorless green ideas sleep furiously.";
            BytestringEncryptor bse = new BytestringEncryptor(publicKey);
            string encryptedText = bse.EncryptString(textToEncrypt);
            string decryptedText = kp.DecryptBase64String(encryptedText);
            Assert.AreEqual(textToEncrypt, decryptedText);
        }
コード例 #2
0
        public void KeyPairDecrypt()
        {
            KeyPair kp = new KeyPair();
            string publicKey = kp.PublicKey;
            StringReader sr = new StringReader(publicKey);
            XmlSerializer xs = new XmlSerializer(typeof(RSAParameters));
            RSAParameters pubKey = (RSAParameters)xs.Deserialize(sr);

            string textToEncrypt = "The limits of my language means the limits of my world.";
            RSACryptoServiceProvider csp = new RSACryptoServiceProvider();
            csp.ImportParameters(pubKey);
            string encryptedText = Convert.ToBase64String(csp.Encrypt(Encoding.Unicode.GetBytes(textToEncrypt), false));

            string decryptedText = kp.DecryptBase64String(encryptedText);
            Assert.AreEqual(textToEncrypt, decryptedText);
        }