using System.Security.Cryptography;
public static void Main()
Console.WriteLine(SimpleStringCipher.Instance.Decrypt("zPPQiapdivBzgYNV1flFYDwWgD7zjqpcdcm5rnSQpU/bOuGwNAnaaXUQ4CH5EVSpEUQfo0qBn/SDFmMqc5P5SCR/cZRNnrlohGjNoBCunKiQXHkAKMxNEZ9WKH2TckrV"));
public class SimpleStringCipher
public byte[] InitVectorBytes;
public const int Keysize = 256;
public static SimpleStringCipher Instance { get; set; }
public static string DefaultPassPhrase { get; set; }
public static byte[] DefaultInitVectorBytes { get; set; }
public static byte[] DefaultSalt { get; set; }
static SimpleStringCipher()
SimpleStringCipher.DefaultPassPhrase = "gsKnGZ041HLL4IM8";
SimpleStringCipher.DefaultInitVectorBytes = Encoding.ASCII.GetBytes("jkE49230Tf093b42");
SimpleStringCipher.DefaultSalt = Encoding.ASCII.GetBytes("hgt!16kl");
SimpleStringCipher.Instance = new SimpleStringCipher();
public SimpleStringCipher() {this.InitVectorBytes = SimpleStringCipher.DefaultInitVectorBytes; }
public string Encrypt(string plainText, string passPhrase = null, byte[] salt = null)
passPhrase = SimpleStringCipher.DefaultPassPhrase;
salt = SimpleStringCipher.DefaultSalt;
byte[] bytes1 = Encoding.UTF8.GetBytes(plainText);
using (Rfc2898DeriveBytes rfc2898DeriveBytes = new Rfc2898DeriveBytes(passPhrase, salt))
byte[] bytes2 = rfc2898DeriveBytes.GetBytes(32);
using (Aes aes = Aes.Create())
aes.Mode = CipherMode.CBC;
using (ICryptoTransform encryptor = aes.CreateEncryptor(bytes2, this.InitVectorBytes))
using (MemoryStream memoryStream = new MemoryStream())
using (CryptoStream cryptoStream = new CryptoStream((Stream) memoryStream, encryptor, CryptoStreamMode.Write))
cryptoStream.Write(bytes1, 0, bytes1.Length);
cryptoStream.FlushFinalBlock();
return Convert.ToBase64String(memoryStream.ToArray());
public string Decrypt(string cipherText, string passPhrase = null, byte[] salt = null)
if (string.IsNullOrEmpty(cipherText))
passPhrase = SimpleStringCipher.DefaultPassPhrase;
salt = SimpleStringCipher.DefaultSalt;
byte[] buffer = Convert.FromBase64String(cipherText);
using (Rfc2898DeriveBytes rfc2898DeriveBytes = new Rfc2898DeriveBytes(passPhrase, salt))
byte[] bytes = rfc2898DeriveBytes.GetBytes(32);
using (Aes aes = Aes.Create())
aes.Mode = CipherMode.CBC;
using (ICryptoTransform decryptor = aes.CreateDecryptor(bytes, this.InitVectorBytes))
using (MemoryStream memoryStream = new MemoryStream(buffer))
using (CryptoStream cryptoStream = new CryptoStream((Stream) memoryStream, decryptor, CryptoStreamMode.Read))
byte[] numArray = new byte[buffer.Length];
int count = cryptoStream.Read(numArray, 0, numArray.Length);
return Encoding.UTF8.GetString(numArray, 0, count);