asp.net DES加密解密
来源:互联网 发布:传奇 经验 数据库 编辑:程序博客网 时间:2024/04/29 18:05
//加密
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
- Python实现的在线保持
- 今天好失落,好无聊。。。。。
- 网页经典代码
- C++的构造函数, 复制构造函数 和operator =
- BCB类中引用LIB
- asp.net DES加密解密
- websphere portal 的几个版本
- 网页经典代码
- 网页经典代码
- 一个Java版的目录拷贝程序
- 极惑彩云南
- -单点登陆的方法-
- 统一测试术语翻译迫在眉睫
- Spring JDBC DAO的两个example