Last active
December 23, 2015 06:38
-
-
Save mariusschulz/6594870 to your computer and use it in GitHub Desktop.
Reformatted code example, see http://stackoverflow.com/questions/18851715/encrypting-and-decrypting-query-string-causes-unknown-text-to-be-appended.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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