示例#1
0
        /// <summary>
        ///  导出私钥或者公钥的RSAParameters对象,并转换为 json格式的字符串
        /// </summary>
        /// <param name="includePrivateParameters">是否包含私钥</param>
        /// <returns></returns>
        public string ExportParameters(bool includePrivateParameters = false)
        {
            CreateRSAInstance();
            RSAParameters paramenter = rsa.ExportParameters(includePrivateParameters);

            return(paramenter.ObjToJson());
        }
示例#2
0
        /// <summary>
        ///  创建一个随机的RSA加密算法的RSAParameters对象,并转换为 json格式的字符串
        /// </summary>
        /// <param name="includePrivateParameters">是否包含私钥</param>
        /// <param name="keySize">加密 key 的长度</param>
        /// <returns></returns>
        public static string GenerateKey(bool includePrivateParameters = true, int keySize = 1024)
        {
            RSA rsager = RSA.Create();

            rsager.KeySize = keySize;
            RSAParameters paramenter = rsager.ExportParameters(includePrivateParameters);

            return(paramenter.ObjToJson());
        }