asp.net DES加密解密
来源:互联网 发布:淘宝物流一直不更新 编辑:程序博客网 时间:2024/04/29 16:20
//加密
public string DesEncrypt(string strText, string strEncrKey)
{
byte[] byKey=null;
byte[] IV= {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF};
try
{
byKey = System.Text.Encoding.UTF8.GetBytes(strEncrKey.Substring(0,8));
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)
{
MessageBox.Show(error.Message);
return "error:" +error.Message+"/r";
}
}
//解密
public string DesDecrypt(string strText,string sDecrKey)
{
byte[] byKey = null;
byte[] IV= {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF};
byte[] inputByteArray = new Byte[strText.Length];
try
{
byKey = System.Text.Encoding.UTF8.GetBytes(sDecrKey.Substring(0,8));
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)
{
MessageBox.Show(error.Message);
return "error:"+error.Message+"/r";
}
}
public string DesEncrypt(string strText, string strEncrKey)
{
byte[] byKey=null;
byte[] IV= {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF};
try
{
byKey = System.Text.Encoding.UTF8.GetBytes(strEncrKey.Substring(0,8));
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)
{
MessageBox.Show(error.Message);
return "error:" +error.Message+"/r";
}
}
//解密
public string DesDecrypt(string strText,string sDecrKey)
{
byte[] byKey = null;
byte[] IV= {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF};
byte[] inputByteArray = new Byte[strText.Length];
try
{
byKey = System.Text.Encoding.UTF8.GetBytes(sDecrKey.Substring(0,8));
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)
{
MessageBox.Show(error.Message);
return "error:"+error.Message+"/r";
}
}
- asp.net DES加密解密
- asp.net DES加密解密
- asp.net DES加密解密
- asp.net DES加密解密
- asp.net中的DES加密解密
- .NET DES加密、解密
- ASP.NET中的DES加密解密,可用于URL传参
- asp.net(C#) 与 flash 传递参数DES加密解密
- ASP的DES加密解密
- .NET中的DES加密解密
- .NET使用DES加密解密
- ASP.NET加密解密
- Asp.Net 加密解密
- ASP.NET加密解密
- ASP.NET--DES加密字符串
- [.net]标准 3DES 加密/解密
- JAVA与.NET DES加密解密
- Java和.net加密解密互通DES
- 软件外包带来的利弊
- 使用input type=file 上传文件时需注意
- 如何带菜鸟员工
- 加密web.config中数据参数的信息
- 千分位显示
- asp.net DES加密解密
- 数据库事务2
- 菜鸟必看!让15个成功人物摇头的坏习惯
- XML的简单读取与写入
- javascript的parseInt进制问题
- C# WinForm中如何打开一个超链接
- 女人要偷偷知道的10件事
- 数据库中与C#中的数据类型对照
- C#编码规范