C# des 加密 解密
2010-05-17 11:11
281 查看
代码
public class EncryptDecrypt
{
public static string EncryptString(string mes, string key)
{
byte[] inputBytes = ASCIIEncoding.UTF8.GetBytes(mes);
MemoryStream outputStream = new MemoryStream();
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
des.Key = ASCIIEncoding.ASCII.GetBytes(key);
des.IV = ASCIIEncoding.ASCII.GetBytes(key);
ICryptoTransform desencrypt = des.CreateEncryptor();
CryptoStream cryptostream = new CryptoStream(outputStream, desencrypt, CryptoStreamMode.Write);
cryptostream.Write(inputBytes, 0, inputBytes.Length);
cryptostream.FlushFinalBlock();
cryptostream.Close();
string outputString = Convert.ToBase64String(outputStream.ToArray());
return outputString;
}
public static string DecryptString(string mes, string key)
{
byte[] inputBytes = Convert.FromBase64String(mes);
MemoryStream outputStream = new MemoryStream();
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
des.Key = ASCIIEncoding.ASCII.GetBytes(key);
des.IV = ASCIIEncoding.ASCII.GetBytes(key);
ICryptoTransform desencrypt = des.CreateDecryptor();
CryptoStream cryptostream = new CryptoStream(outputStream, desencrypt, CryptoStreamMode.Write);
cryptostream.Write(inputBytes, 0, inputBytes.Length);
cryptostream.FlushFinalBlock();
cryptostream.Close();
string outputString = ASCIIEncoding.UTF8.GetString(outputStream.ToArray());
return outputString;
}
}
public class EncryptDecrypt
{
public static string EncryptString(string mes, string key)
{
byte[] inputBytes = ASCIIEncoding.UTF8.GetBytes(mes);
MemoryStream outputStream = new MemoryStream();
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
des.Key = ASCIIEncoding.ASCII.GetBytes(key);
des.IV = ASCIIEncoding.ASCII.GetBytes(key);
ICryptoTransform desencrypt = des.CreateEncryptor();
CryptoStream cryptostream = new CryptoStream(outputStream, desencrypt, CryptoStreamMode.Write);
cryptostream.Write(inputBytes, 0, inputBytes.Length);
cryptostream.FlushFinalBlock();
cryptostream.Close();
string outputString = Convert.ToBase64String(outputStream.ToArray());
return outputString;
}
public static string DecryptString(string mes, string key)
{
byte[] inputBytes = Convert.FromBase64String(mes);
MemoryStream outputStream = new MemoryStream();
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
des.Key = ASCIIEncoding.ASCII.GetBytes(key);
des.IV = ASCIIEncoding.ASCII.GetBytes(key);
ICryptoTransform desencrypt = des.CreateDecryptor();
CryptoStream cryptostream = new CryptoStream(outputStream, desencrypt, CryptoStreamMode.Write);
cryptostream.Write(inputBytes, 0, inputBytes.Length);
cryptostream.FlushFinalBlock();
cryptostream.Close();
string outputString = ASCIIEncoding.UTF8.GetString(outputStream.ToArray());
return outputString;
}
}
相关文章推荐
- [网络收集]C# 各种加密,解密算法【MD5,DES,线性,卷帘】
- c# des 加密解密
- DES 加密/解密-C#
- C#中使用DES和AES加密解密
- C# DES 加密/解密类库,支持文件和中文/UNICODE字符,返回BASE64编码字符串
- C# 加密解密(DES,3DES,MD5,Base64) 类
- C#中使用DES和AES加密解密
- C# DES 加密解密
- 【转】asp.net(c#)加密解密算法之sha1、md5、des、aes实现源码详解
- [转]C# DES 加密/解密类库,支持文件和中文/UNICODE字符,返回BASE64编码字符串
- C#加密解密(DES,AES,Base64,md5,SHA256,RSA,RC4)
- 用 Java 解密 C# 加密的数据(DES)
- C#中使用DES和AES加密解密
- 黄聪:C# DES 加密/解密类库,支持文件和中文/UNICODE字符,返回BASE64编码字符串
- c# 调用PB中的b64_size加密解密 DES
- C#字符串的加密与解密(DES和TripleDES算法的加密解密过程)
- C# 與JAVA 共用的DES 加密解密方法
- [读书笔记]C# DES 加密/解密类库,支持文件和中文/UNICODE字符,返回BASE64编码字符串
- C# 加密解密(DES,3DES,MD5,Base64) 类
- Java加密和C#解密=>DES方法