关于DES加密解决办法

本文详细介绍了如何使用.NET框架中的DES加密算法对数据进行加密和解密。通过具体的代码示例,展示了如何创建加密和解密函数,并在按钮点击事件中调用这些函数来处理文件内容。

关于.net 的DES加密解决办法
EDS加密是一个分组加密算法,通过64位分组对数据进行加密。设计EDS加密程序

Public static string EncodeDES(string encryptString, string encryptkey)
{
  Try
{
   Byte[]rgbkey=encoding.UTF8.Getbytes(encryptkey.Substring(0,8));
   Byte[]rgbIV=keyIV;
   Byte[]inputArray=encoding.UTE8.Getbytes(encryptString);
   DESCryptoservicePrvider desCSP= DESCryptoservicePrvider();
   MemoryStream mStream=new MemoryStream();
   CryptoStream cStream=new CryptoStream(mStream, desCSP.CreateEncryptor(rgbKey, rgbIV),
CryptoStreamMode.Write);
       cSteam.Write(inputArray,0,inputArray.Length);
       cSteam.FlushFinalBlock()
       return Convert. ToBase64String(mStream.ToArray());
      }
Catch 
{
    Return encryptString;
}
}
设计解码程序
Public static string DecodeDES(string decryptString, string decryptkey)
{
  Try
{
   Byte[]rgbkey=Encoding.UTF8.Getbytes(Decryptkey.Substring(0,8));
   Byte[]rgbIV=keyIV;
   Byte[]inputArray=encoding.UTE8.Getbytes(decryptString);
   DESCryptoservicePrvider desCSP= new DESCryptoservicePrvider();
   MemoryStream mStream=new MemoryStream();
   CryptoStream cStream=new CryptoStream(mStream, desCSP. CreateEncryptor(rgbKey, rgbIV),
CryptoStreamMode .Write);
       cSteam.Write(inputArray,0, inputArray. Length);
       cSteam. FlushFinalBlock()
       return Convert. ToBase64String(mStream.ToArray());
      }
Catch 
{
    Return decryptString;
}
}
为btnEncode添加事件,实现DES加密
Private viod btnEncode_Click(objiect sender, EventArgs e)
{
	StreamRadear datain=File.OpenTxet(tbBeforeCrypFile.Text);
String strTmp;
ArrayList alldate =new Arraylist();
While((strTmp=datain.ReadLine())!=null)
{
		Alldate.Add(strTmp);
}
Foreach(string str in alldate)
{
	tbBeforeCrypContent.Text+=str;
	tbBeforeCrypContent.Text+=\r\n”;
try
{
		String temp= tbBeforeCrypContent.Text;
		tbBeforeCrypContent.Text=EncodeDES(temp,keyDes);
}
Catch(System.Exception ep)
{
		MassageBox.Show(ep.Mssage);
}
FileSteam fileSteam=new fileSteam(tbAfterCrypFile.Text,filemode.openorcreate);
Steamwriter steamwriter=new steamwriter(filesteam)
//开始写入
Steamwrite.write(tbaftercrypcontent.text);
//清空缓存
Streamwriter.flush();
//关闭流
Steamwrite.close();
Filesteam.close();
}
为btnDecode添加事件,实现DES解密
Private viod btndecode_click(object sender,eventargse)
  {
	Try
		{
			String temp=tbaftercrypcontent.text;
              tbaftercrypcontent.text=decodeDES(temp,keydes);
          }
      Catch(System.Exception ep)
{
Massagebox.show(ep.massage)
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

飞天的大鹅

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值