0

So I recently started encrypting all the query string parameters and now the problem i have is to check for null value

 if ((Security.DecryptQueryString(HttpUtility.UrlDecode(Request.QueryString["Artigo"]))) != null)
 {                        
       int artigoID = Convert.ToInt32(Security.DecryptQueryString(HttpUtility.UrlDecode(Request.QueryString["Artigo"])));
       hdfIdArtigo.Value = artigoID.ToString();
       BindDraftMode(artigoID);
 }

this gives me an exception of object not being set to an instance of object...

How do you check the null value when value is encrypted or when there is no value? Problem is when I am not sending any parameters to the other page so I don't know how to check for value when is encrypted

EDIT:

here is decryption function

    public static string DecryptQueryString(string cipherText)
    {
        string EncryptionKey = "hyddhrii%2moi43Hd5%%";
        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;
    }
Jackal
  • 3,359
  • 4
  • 33
  • 78

0 Answers0