using System.Security.Cryptography;
private byte[] Key = { 123, 117, 19, 11, 24, 16, 85, 45, 164, 184, 27, 162, 37, 112, 222, 12, 241, 24, 175, 144, 173, 53, 146, 129, 24, 26, 17, 218, 131, 236, 53, 219 };
private byte[] Vector = { 146, 34, 111, 111, 23, 3, 113, 119, 231, 121, 151, 112, 79, 32, 114, 246 };
private ICryptoTransform EncryptorTransform, DecryptorTransform;
private System.Text.UTF8Encoding UTFEncoder;
var rm = Aes.Create("AesManaged");
EncryptorTransform = rm.CreateEncryptor(this.Key, this.Vector);
DecryptorTransform = rm.CreateDecryptor(this.Key, this.Vector);
UTFEncoder = new System.Text.UTF8Encoding();
public string EncryptToString(string TextValue)
string ret = enc(TextValue);
string enc(string textToEncrypt)
int m = int.Parse(textToEncrypt) * salt;
return EncodeTo64(XOR(m.ToString()));
string deenc(string textToEncrypt)
int m = int.Parse(XOR(DecodeFrom64(textToEncrypt))) / salt;
public string EncodeTo64(string toEncode)
byte[] bytesToEncode = System.Text.Encoding.UTF8.GetBytes(toEncode);
string base64String = Convert.ToBase64String(bytesToEncode);
public string DecodeFrom64(string encodedData)
byte[] encodedDataAsBytes = Convert.FromBase64String(encodedData);
string returnValue = Encoding.UTF8.GetString(encodedDataAsBytes);
public string XOR(string text)
string key = "ASIodhp893dp()?SH dsjp a";
StringBuilder result = new StringBuilder();
for (int c = 0; c < text.Length; c++)
char character = text[c];
uint charCode = (uint)character;
int keyPosition = c % key.Length;
char keyChar = key[keyPosition];
uint keyCode = (uint)keyChar;
uint combinedCode = charCode ^ keyCode;
char combinedChar = (char)combinedCode;
result.Append(combinedChar);
return result.ToString();
byte[] Encrypt(string TextValue)
Byte[] bytes = UTFEncoder.GetBytes(TextValue);
MemoryStream memoryStream = new MemoryStream();
CryptoStream cs = new CryptoStream(memoryStream, EncryptorTransform, CryptoStreamMode.Write);
cs.Write(bytes, 0, bytes.Length);
memoryStream.Position = 0;
byte[] encrypted = new byte[memoryStream.Length];
memoryStream.Read(encrypted, 0, encrypted.Length);
public string DecryptString(string EncryptedString)
if (EncryptedString.Length > 15)
return Decrypt(StrToByteArray(EncryptedString));
return deenc(EncryptedString);
string Decrypt(byte[] EncryptedValue)
MemoryStream encryptedStream = new MemoryStream();
CryptoStream decryptStream = new CryptoStream(encryptedStream, DecryptorTransform, CryptoStreamMode.Write);
decryptStream.Write(EncryptedValue, 0, EncryptedValue.Length);
decryptStream.FlushFinalBlock();
encryptedStream.Position = 0;
Byte[] decryptedBytes = new Byte[encryptedStream.Length];
encryptedStream.Read(decryptedBytes, 0, decryptedBytes.Length);
return UTFEncoder.GetString(decryptedBytes);
byte[] StrToByteArray(string str)
throw new Exception("Invalid string value in StrToByteArray");
byte[] byteArr = new byte[str.Length / 3];
val = byte.Parse(str.Substring(i, 3));
string ByteArrToString(byte[] byteArr)
for (int i = 0; i <= byteArr.GetUpperBound(0); i++)
tempStr += "00" + val.ToString();
else if (val < (byte)100)
tempStr += "0" + val.ToString();
tempStr += val.ToString();
public static void Main()
var x = aes.EncryptToString("145");
var y = aes.DecryptString("cGRxVldY");