/// <summary> /// 加密 /// </summary> /// <param name="Source">待加密字符串</param> /// <param name="PublicKey">公钥</param> /// <returns></returns> public string Encrypt(string Source, string PublicKey) { string base64Encode = Base64Encrypt.EncryptString(Source); rsa.FromXmlString(PublicKey); byte[] done = rsa.Encrypt(Convert.FromBase64String(base64Encode), false); return(Convert.ToBase64String(done)); }
/// <summary> /// 解密 /// </summary> /// <param name="Source">待解密字符串</param> /// <param name="PrivateKey">私钥</param> /// <returns></returns> public string Decrypt(string Source, string PrivateKey) { rsa.FromXmlString(PrivateKey); byte[] done = rsa.Decrypt(Convert.FromBase64String(Source), false); string base64Decode = Base64Encrypt.DecryptString(Convert.ToBase64String(done)); return(base64Decode); }