关于DES加密解决办法

飞天的大鹅 飞天的大鹅 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
关于.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) } }
...全文
评论 1
收藏 已收藏
分享
返回顶部
飞天的大鹅
.NET Framework 17,748 成员 24,324 内容