啾啾啾~
public class DecryptionTool
{
/// <summary>
/// RSA加密
/// </summary>
/// <param name="strText">待加密内容</param>
/// <param name="strPublicKey">公钥</param>
/// <returns></returns>
public string Encrypt(string strText, string strPublicKey)
{
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
rsa.FromXmlString(strPublicKey);
byte[] byteText = Encoding.UTF8.GetBytes(strText);
byte[] byteEntry = rsa.Encrypt(byteText, false);
return Convert.ToBase64String(byteEntry);
}
/// <summary>
/// RSA解密
/// </summary>
/// <param name="strEntryText">待解密</param>
/// <param name="strPrivateKey">私钥</param>
/// <returns></returns>
public string Decrypt(string strEntryText, string strPrivateKey)
{
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
rsa.FromXmlString(strPrivateKey);
byte[] byteEntry = Convert.FromBase64String(strEntryText);
byte[] byteText = rsa.Decrypt(byteEntry, false);
return Encoding.UTF8.GetString(byteText);
}
/// <summary>
/// 获取密钥
/// </summary>
/// <returns></returns>
public Dictionary<string, string> GetKey()
{
Dictionary<string, string> dictKey =