using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Security.Cryptography;
public static readonly string DefaultDesKey = "Xx%#lA*1";
public static readonly string DefaultDesIv = "Xx%#lA*1";
public static void Main()
Console.WriteLine("Hello World");
var test = DesDecryptSafe("I_7qt5o3zJAJr9XptNoJEw2",DefaultDesKey, DefaultDesIv);
public static string DesDecryptSafe(string encryptedString, string key, string iv)
string result = string.Empty;
byte[] btKey = Encoding.UTF8.GetBytes(key);
byte[] btIV = Encoding.UTF8.GetBytes(iv);
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
using (MemoryStream ms = new MemoryStream())
byte[] inData = HttpServerUtility.UrlTokenDecode(encryptedString);
using (CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(btKey, btIV), CryptoStreamMode.Write))
cs.Write(inData, 0, inData.Length);
result = Encoding.UTF8.GetString(ms.ToArray());
result = encryptedString;
public static string DesEncryptSafe(string sourceString, string key, string iv)
string result = string.Empty;
byte[] btKey = Encoding.UTF8.GetBytes(key);
byte[] btIV = Encoding.UTF8.GetBytes(iv);
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
using (MemoryStream ms = new MemoryStream())
byte[] inData = Encoding.UTF8.GetBytes(sourceString);
using (CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(btKey, btIV), CryptoStreamMode.Write))
cs.Write(inData, 0, inData.Length);
result = HttpServerUtility.UrlTokenEncode(ms.ToArray());