encryptstring
DESCryptoServiceProvider desc = new DESCryptoServiceProvider();
byte[] key = System.Text.Encoding.Unicode.GetBytes(encryptkey);
byte[] data = System.Text.Encoding.Unicode.GetBytes(encryptstring);
MemoryStream ms = new MemoryStream();//存储加密后的数据
CryptoStream cs = new CryptoStream(ms, desc.CreateEncryptor(key, key), CryptoStreamMode.Write);
cs.Write(data, 0, data.Length);//进行加密
cs.FlushFinalBlock();
strRtn = Convert.ToBase64String(ms.ToArray());
return strRtn;
decryptstring
DESCryptoServiceProvider desc = new DESCryptoServiceProvider();
byte[] key = System.Text.Encoding.Unicode.GetBytes(encryptkey);
byte[] data = Convert.FromBase64String(decryptstring);
MemoryStream ms = new MemoryStream();//存储解密后的数据
CryptoStream cs = new CryptoStream(ms, desc.CreateDecryptor(key, key), CryptoStreamMode.Write);
cs.Write(data, 0, data.Length);//解密数据
cs.FlushFinalBlock();
strRtn = System.Text.Encoding.Unicode.GetString(ms.ToArray());
return strRtn;