#region RijndaelManaged加密
/// <summary>
/// 加密数据
/// </summary>
/// <param name="Text">要加密的内容</param>
/// <param name="sKey">key,必须为32位</param>
/// <returns></returns>
public static string RiEncrypt(string Text, string sKey)
{
byte[] keyArray = UTF8Encoding.UTF8.GetBytes(sKey);
//TripleDESCryptoServiceProvider
RijndaelManaged encryption = new RijndaelManaged();
encryption.Key = keyArray;
encryption.Mode = CipherMode.ECB;
encryption.Padding = PaddingMode.PKCS7;
ICryptoTransform cTransform = encryption.CreateEncryptor();
byte[] _EncryptArray = UTF8Encoding.UTF8.GetBytes(Text);
byte[] resultArray = cTransform.TransformFinalBlock(_EncryptArray, , _EncryptArray.Length);
return Convert.ToBase64String(resultArray, , resultArray.Length);
}
#endregion
#region =======RijndaelManaged解密========
/// <summary>
/// 解密数据
/// </summary>
/// <param name="Text"></param>
/// <param name="sKey"></param>
/// <returns></returns>
public static string RiDecrypt(string Text, string sKey)
{
byte[] keyArray = UTF8Encoding.UTF8.GetBytes(sKey);
RijndaelManaged decipher = new RijndaelManaged();
decipher.Key = keyArray;
decipher.Mode = CipherMode.ECB;
decipher.Padding = PaddingMode.PKCS7;
ICryptoTransform cTransform = decipher.CreateDecryptor();
byte[] _EncryptArray = Convert.FromBase64String(Text);
byte[] resultArray = cTransform.TransformFinalBlock(_EncryptArray, , _EncryptArray.Length);
return UTF8Encoding.UTF8.GetString(resultArray);
}
#endregion