c#实现DES加密与解密
来源:互联网 发布:mysql服务器安装包 编辑:程序博客网 时间:2024/04/27 21:24
//DES加密
public string DESEncrypt(string pToEncrypt, string sKey)
...{
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
byte[] inputByteArray = Encoding.Default.GetBytes(pToEncrypt);
des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(),CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
StringBuilder ret = new StringBuilder();
foreach(byte b in ms.ToArray())
...{
ret.AppendFormat("{0:X2}", b);
}
ret.ToString();
return ret.ToString();
}
//DES解密
public string DESDecrypt(string pToDecrypt, string sKey)
...{
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
byte[] inputByteArray = new byte[pToDecrypt.Length / 2];
for(int x = 0; x < pToDecrypt.Length / 2; x++)
...{
int i = (Convert.ToInt32(pToDecrypt.Substring(x * 2, 2), 16));
inputByteArray[x] = (byte)i;
}
des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(),CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
StringBuilder ret = new StringBuilder();
return System.Text.Encoding.Default.GetString(ms.ToArray());
}
public string DESEncrypt(string pToEncrypt, string sKey)
...{
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
byte[] inputByteArray = Encoding.Default.GetBytes(pToEncrypt);
des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(),CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
StringBuilder ret = new StringBuilder();
foreach(byte b in ms.ToArray())
...{
ret.AppendFormat("{0:X2}", b);
}
ret.ToString();
return ret.ToString();
}
//DES解密
public string DESDecrypt(string pToDecrypt, string sKey)
...{
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
byte[] inputByteArray = new byte[pToDecrypt.Length / 2];
for(int x = 0; x < pToDecrypt.Length / 2; x++)
...{
int i = (Convert.ToInt32(pToDecrypt.Substring(x * 2, 2), 16));
inputByteArray[x] = (byte)i;
}
des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(),CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
StringBuilder ret = new StringBuilder();
return System.Text.Encoding.Default.GetString(ms.ToArray());
}
- c#实现DES加密与解密
- C# DES加密与解密
- 用C#实现DES加密解密封装
- 用C#实现DES加密解密
- C#实现Des加密和解密
- C# 实现3Des加密 解密 - SummerA
- 用C#实现DES加密解密
- c# DES加密与解密代码
- C#语法 DES加密与解密
- C#实现DES加密解密,AES加密解密
- c# DES 加密解密
- c# des 加密解密
- DES 加密/解密-C#
- c# DES加密解密
- c# DES 加密解密
- c# des 加密 解密
- DES加密与解密算法的实现
- java实现DES数据加密与解密
- Domino基本概念
- C++ 370-24题-1 继承
- 编程设计:61条面向对象设计的经验原则
- 大型网站设计注意事项
- C++ 370-24题-2 继承基类
- c#实现DES加密与解密
- 在类中实现的接口的方法需要加上“public”关键字
- Visual Studio .NET 无法创建或打开应用程序。问题很可能是因为本地Web服务器上没有安装所需的组件。请运行Visual Studio .NET安装程序并
- 突破google快照的限制
- 巧用GOOGLE突破网站限制免费在线翻译
- 代码移植中的诡异bug
- ✿ mac苹果机 WinXP安装图文 (下)
- ✿ mac苹果机 WinXP安装图文 (上)
- C++ 372-24题 点派生求矩形面积