using System.Collections.Generic;
using System.Security.Cryptography;
public static string strKey = "11223344";
public static string strIV = "HdsAdmin";
public static void Main()
Console.WriteLine(Encrypt("KB30002012"));
Console.WriteLine(Decrypt("itpXB9HkOmOEaCOV5XS4CA=="));
public static string Encrypt(string _strQ)
if (String.IsNullOrEmpty(_strQ))
byte[] buffer = Encoding.UTF8.GetBytes(_strQ);
MemoryStream ms = new MemoryStream();
DESCryptoServiceProvider tdes = new DESCryptoServiceProvider();
CryptoStream encStream = new CryptoStream(ms, tdes.CreateEncryptor(Encoding.UTF8.GetBytes(strKey), Encoding.UTF8.GetBytes(strIV)), CryptoStreamMode.Write);
encStream.Write(buffer, 0, buffer.Length);
encStream.FlushFinalBlock();
return Convert.ToBase64String(ms.ToArray()).Replace("+", "%");
public static string Decrypt(string _strQ)
_strQ = _strQ.Replace("%", "+");
byte[] buffer = Convert.FromBase64String(_strQ);
MemoryStream ms = new MemoryStream();
DESCryptoServiceProvider tdes = new DESCryptoServiceProvider();
CryptoStream encStream = new CryptoStream(ms, tdes.CreateDecryptor(Encoding.UTF8.GetBytes(strKey), Encoding.UTF8.GetBytes(strIV)), CryptoStreamMode.Write);
encStream.Write(buffer, 0, buffer.Length);
encStream.FlushFinalBlock();
return Encoding.UTF8.GetString(ms.ToArray());