Esempio n. 1
0
        public static void rsaByGenKey(int size, string content)
        {//
            RSASecretKey key = RSAUtils.GenerateRSASecretKey(size);
            string       en  = RSAUtils.RSAEncrypt(key.PublicKey, content);
            string       de  = RSAUtils.RSADecrypt(key.PrivateKey, en);

            Console.WriteLine(de);
            Console.ReadKey();
        }
Esempio n. 2
0
        public static RSASecretKey GenerateRSASecretKey(int keySize)
        {
            RSASecretKey rsaKey = new RSASecretKey();

            using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(keySize))
            {
                rsaKey.PrivateKey = rsa.ToXmlString(true);//true 表示同时包含 RSA 公钥和私钥;false 表示仅包含公钥。
                rsaKey.PublicKey  = rsa.ToXmlString(false);
            }
            return(rsaKey);
        }