c#的winform系统,实现多页签, 重点有AES加密与解密原码及完整实例 private void btnEncrypt_Click(object sender, EventArgs e)
{
getrmParams();
txtTo.Text = DmLib.AesEncrypt(rmTextFrom, rmKey, rmIv, rmMode, rmPadding, rmBlockSize, rmOutput);
}
private void btnDecrypt_Click(object sender, EventArgs e)
{
getrmParams();
string str = DmLib.AesDecrypt(rmTextTo, rmKey, rmIv, rmMode, rmPadding, rmBlockSize, rmOutput);
txtFrom.Text = str;
}
/// <summary>
/// AES加密
/// </summary>
/// <param name="text">加密字符</param>
/// <param name="key">加密的密码</param>
/// <param name="iv">密钥</param>
/// <returns></returns>
public static string AesEncrypt(string text, string key, string iv
, CipherMode rmMode = CipherMode.ECB, PaddingMode rmPadding = PaddingMode.Zeros, int rmBlockSize = 128, string rmOutput = "hex")
{
RijndaelManaged rm = new RijndaelManaged();
rm.Mode = rmMode; //加密模式
rm.Padding = rmPadding; //填充
rm.BlockSize = rmBlockSize; //数据块
rm.KeySize = rmBlockSize;
....
return str;
}
/// <summary>
/// AES解密
/// </summary>
/// <param name="text"></param>
/// <param name="key"></param>
/// <param name="iv"></param>
/// <returns></returns>
public static string AesDecrypt(string text, string key, string iv
, CipherMode rmMode = CipherMode.ECB, PaddingMode rmPadding = PaddingMode.Zeros, int rmBlockSize = 128, string rmOutput = "hex")
{
RijndaelManaged rm = new RijndaelManaged();
rm.Mode = rmMode;
rm.Padding = rmPadding;
rm.BlockSize = rmBlockSize;
rm.KeySize = rmBlockSize;
....
}
评论