关于DES加密解决办法

飞天的大鹅 2019-08-01 03:00:37
关于.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) } }
...全文
170 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
XBodhi. 2019-08-01
  • 打赏
  • 举报
回复
你要实现什么,有相关的对象。

17,741

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 .NET Framework
社区管理员
  • .NET Framework社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧