예제 #1
0
파일: Rsa.cs 프로젝트: wingahi/CSHive
        /// <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));
        }
예제 #2
0
파일: Rsa.cs 프로젝트: wingahi/CSHive
        /// <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));
        }
예제 #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);
 }
예제 #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);
 }
예제 #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));
        }
예제 #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));
        }