Ejemplo n.º 1
0
        /// <summary>
        /// 用私钥解密经加密后的Base64字符串
        /// </summary>
        /// <param name="base64Source"></param>
        /// <param name="privateKey"></param>
        /// <returns></returns>
        public static string Decrypt(string base64Source, string privateKey)
        {
            var bs  = Convert.FromBase64String(base64Source);
            var rsa = new Rsa(privateKey);
            var rst = rsa.Decrypt(bs);

            return(Encoding.UTF8.GetString(rst));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 用公钥加密字符串
        /// </summary>
        /// <param name="source">源有长度限制</param>
        /// <param name="publicKey"></param>
        /// <returns>返回加密后的Base64字符串</returns>
        public static string Encrypt(string source, string publicKey)
        {
            var bs  = Encoding.UTF8.GetBytes(source);
            var rsa = new Rsa(publicKey);
            var rst = rsa.Encrypt(bs);

            return(Convert.ToBase64String(rst));
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 解密出原始Key
 /// </summary>
 /// <param name="token"></param>
 /// <returns></returns>
 public static byte[] DeRsaKey(byte[] token)
 {
     var rsa = new Rsa(PrivateKey);
     return rsa.Decrypt(token);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 将Key用RSA加密
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public static byte[] RsaKey(byte[] key)
 {
     var rsa = new Rsa(PublicKey);
     return rsa.Encrypt(key);
 }
Ejemplo n.º 5
0
        /// <summary>
        /// 解密出原始Key
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        public static byte[] DeRsaKey(byte[] token)
        {
            var rsa = new Rsa(PrivateKey);

            return(rsa.Decrypt(token));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 将Key用RSA加密
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static byte[] RsaKey(byte[] key)
        {
            var rsa = new Rsa(PublicKey);

            return(rsa.Encrypt(key));
        }