예제 #1
0
        /// <summary>
        /// 生成 RSA 公钥和私钥
        /// </summary>
        public static RsaKey GenerateRsaKeys(int length = 1024)
        {
            var rsa = new RSA(length);

            return(RsaKey = new RsaKey
            {
                PrivateKey = rsa.ToPEM_PKCS1(),
                PublicKey = rsa.ToPEM_PKCS1(true)
            });
        }
예제 #2
0
 /// <summary>
 /// 生成 RSA 公钥和私钥
 /// </summary>
 public static RsaKey GenerateRsaKeys()
 {
     using (var rsa = new RSACryptoServiceProvider())
     {
         return(RsaKey ?? (RsaKey = new RsaKey
         {
             PrivateKey = rsa.ToXmlString(true),
             PublicKey = rsa.ToXmlString(false)
         }));
     }
 }