/// <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)); }
/// <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)); }
/// <summary> /// 解密出原始Key /// </summary> /// <param name="token"></param> /// <returns></returns> public static byte[] DeRsaKey(byte[] token) { var rsa = new Rsa(PrivateKey); return rsa.Decrypt(token); }
/// <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); }
/// <summary> /// 解密出原始Key /// </summary> /// <param name="token"></param> /// <returns></returns> public static byte[] DeRsaKey(byte[] token) { var rsa = new Rsa(PrivateKey); return(rsa.Decrypt(token)); }
/// <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)); }