Skip to content

Instantly share code, notes, and snippets.

@mariusschulz
Last active December 23, 2015 06:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mariusschulz/6594870 to your computer and use it in GitHub Desktop.
Save mariusschulz/6594870 to your computer and use it in GitHub Desktop.
public string DecryptQueryString(string inputText, string key, string salt)
{
byte[] encryptedData = Convert.FromBase64String(inputText);
var secretKey = new PasswordDeriveBytes(Encoding.ASCII.GetBytes(key), Encoding.ASCII.GetBytes(salt));
using (var rijndaelCipher = new RijndaelManaged())
using (var decryptor = rijndaelCipher.CreateDecryptor(secretKey.GetBytes(32), secretKey.GetBytes(16)))
using (var memoryStream = new MemoryStream(encryptedData))
using (var cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read))
{
byte[] plainText = new byte[encryptedData.Length];
cryptoStream.Read(plainText, 0, plainText.Length);
return Encoding.UTF8.GetString(plainText);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment