对称加密问题,高分求助!

ywcyj 2004-07-02 02:17:43
我写对称加密函数,遇到一个问题:不认识键盘上的&字符,其他字符好像都没问题。大家帮我看看如何修改程序:
源代码如下:
//加密字符串
public string DesEncrypt(string strText)
{ try
{
byte[] byKey = byte[] IV= {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF};
byte[] IV = byte[] IV= {0x23, 0x45, 0x67, 0x89, 0x0A, 0xBC, 0xDE, 0xF1};

DESCryptoServiceProvider des = new DESCryptoServiceProvider();
byte[] inputByteArray = System.Text.Encoding.UTF8.GetBytes(strText);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(byKey, IV), CryptoStreamMode.Write) ;
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
return Convert.ToBase64String(ms.ToArray());
}
catch(System.Exception error)
{
return "error:" +error.Message+"\r";
}
}

//解密字符串
public string DesDecrypt(string strText)
{
try
{
byte[] byKey = byte[] IV= {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF};
byte[] IV = byte[] IV= {0x23, 0x45, 0x67, 0x89, 0x0A, 0xBC, 0xDE, 0xF1};

byte[] inputByteArray = new Byte[strText.Length];
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
inputByteArray = Convert.FromBase64String(strText);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(byKey, IV), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
System.Text.Encoding encoding = new System.Text.UTF8Encoding();
return encoding.GetString(ms.ToArray());
}
catch(System.Exception error)
{
return "error:"+error.Message+"\r";
}
}
...全文
197 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
edobnet 2004-07-09
  • 打赏
  • 举报
回复
换一种算法,
ywcyj 2004-07-09
  • 打赏
  • 举报
回复
我的问题没人知道吗?
高手在哪里?
ywcyj 2004-07-09
  • 打赏
  • 举报
回复
经过测试,
http://community.csdn.net/Expert/FAQ/FAQ_Index.asp?id=35935
实现的效果和我写的代码一摸一样
&字符经过加密解密后,就不见了,而后面紧跟者的字符下面出现了_字符,的确比较怪
ywcyj 2004-07-09
  • 打赏
  • 举报
回复
谢谢大象,我试试
CMIC 2004-07-09
  • 打赏
  • 举报
回复
用这个,这个支持&字符
使用DES对称加密代码,可以加密码,可以加密解密,支持中文!
http://community.csdn.net/Expert/FAQ/FAQ_Index.asp?id=35935
ywcyj 2004-07-05
  • 打赏
  • 举报
回复
@可不敢随便加
加了@,字符串就变长了
@字符也是有效字符呀
wuzhijie 2004-07-03
  • 打赏
  • 举报
回复
在字符串前加@

111,093

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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