Here I will brief you about how to handle it on destination Side. As we saw we have done an encryption using a key ; now we need to use the same key to decrypt the information from Encrypted text.For this firstly we need to fetch the information from Query String and then decode this using UrlDecode of HttpUtility class.
Please find below is the helper method to encrypt parameters:
- using System.Security.Cryptography;
- private string Decrypt(string cipherText)
- {
- string EncryptionKey = "MAKV2SPBNI99212";
- cipherText = cipherText.Replace(" ", "+");
- byte[] cipherBytes = Convert.FromBase64String(cipherText);
- using (Aes encryptor = Aes.Create())
- {
- Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });
- encryptor.Key = pdb.GetBytes(32);
- encryptor.IV = pdb.GetBytes(16);
- using (MemoryStream ms = new MemoryStream())
- {
- using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateDecryptor(), CryptoStreamMode.Write))
- {
- cs.Write(cipherBytes, 0, cipherBytes.Length);
- cs.Close();
- }
- cipherText = Encoding.Unicode.GetString(ms.ToArray());
- }
- }
- return cipherText;
- }
- string Location = "SharepointUserLocation";
- string LoggedInUser = "SharepointUser";
- string EncryptedLocation = Encrypt(HttpUtility.UrlEncode(Location .Trim()));
- string EncryptedLoggedInUser = Encrypt(HttpUtility.UrlEncode(LoggedInUser.Trim()));
- string Encrypted = string.Format("~/page.aspx?Location={0}&LoggedInUser={1}", EncryptedLocation , EncryptedLoggedInUser);
- string decryptedLocation = Decrypt(HttpUtility.UrlDecode(EncryptedLocation));
- string decryptedLoggedInUser = Decrypt(HttpUtility.UrlDecode(EncryptedLoggedInUser));
- string decrypted = string.Format("~/page.aspx?Location={0}&LoggedInUser={1}", decryptedLocation, decryptedLoggedInUser);

Join the conversation! Your thoughts help the community grow.