Ejemplo n.º 1
0
        /// <summary>
        /// 签名
        /// </summary>
        /// <param name="str">需要签名的字符串</param>
        /// <param name="privateKey">私钥</param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static string RSASign(this string str, string privateKey, RSAType type = RSAType.RSA2)
        {
            RSAHelper helper = new RSAHelper(type, Encoding.UTF8, privateKey);

            return(helper.Sign(str));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 验证签名
        /// </summary>
        /// <param name="str">需要验签的字符串</param>
        /// <param name="sign">签名</param>
        /// <param name="publicKey">公钥</param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static bool RSAVerify(this string str, string sign, string publicKey, RSAType type = RSAType.RSA2)
        {
            RSAHelper helper = new RSAHelper(type, Encoding.UTF8, null, publicKey);

            return(helper.Verify(str, sign));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// RSA加密
        /// </summary>
        /// <param name="str">需要加密的内容</param>
        /// <param name="publicKey">公钥</param>
        /// <param name="type">类型(加密算法类型 RSA SHA1 长度不限制,推荐使用2048位以上;RSA2 SHA256 密钥长度至少为2048)</param>
        /// <returns></returns>
        public static string RSAEncrypt(this string str, string publicKey, RSAType type = RSAType.RSA2)
        {
            RSAHelper helper = new RSAHelper(type, Encoding.UTF8, null, publicKey);

            return(helper.Encrypt(str));
        }