Beispiel #1
0
        public void TestRSA2()
        {
            RSA rsa = new RSA();

            // 生成一组公私钥
            RSA.RSAKEY keyStore = rsa.GetKey();
            string     pubKey   = keyStore.PublicKey;
            string     priKey   = keyStore.PrivateKey;

            string ming = "1234567890123456";

            // 私钥加密,公钥解密
            string mi    = rsa.EncryptByPrivateKey(ming, priKey);
            string ming2 = rsa.DecryptByPublicKey(mi, pubKey);

            Assert.IsTrue(ming == ming2);

            // 公钥加密,私钥解密
            mi    = rsa.EncryptByPublicKey(ming, pubKey);
            ming2 = rsa.DecryptByPrivateKey(mi, priKey);
            Assert.IsTrue(ming == ming2);
        }