3

I have the following ampscript above a landing page unsubscribe form. It appears as though the EncryptSymmetric from the test email and DecryptSymmetric on the landing page are working as expected, but when I try to use the decrypted subKey and email address, it says that they are invalid email addresses even though they look valid upon displaying these strings on the landing page.

AMPSCRIPT:

%%[
 /* Decrypt subscriber key */
  SET @encSubKey = Replace(Replace(Replace(RequestParameter("k"), "-", "+"), "_", "/"), ",", "=")
  SET @subKey =  DecryptSymmetric(@encSubKey, "des;mode=ecb;padding=zeros", @null, @password, @null, @null, @null, @null)
  SET @isValidSubKey = IsEmailAddress(@subKey)
  ]%% 
subKey '%%=v(@subKey)=%%' is valid email address = %%=v(@isValidSubKey)=%% %%[ /* Decrypt email address */ SET @encEmail = Replace(Replace(Replace(RequestParameter("e"), "-", "+"), "_", "/"), ",", "=") SET @email = DecryptSymmetric(@encEmail, "des;mode=ecb;padding=zeros", @null, @password, @null, @null, @null, @null) SET @isValidEmail = IsEmailAddress(@email) ]%%
email '%%=v(@email)=%%' is valid email address = %%=v(@isValidEmail)=%% %%[ ...

BROWSER OUPUT:

subKey 'myemail@example.com' is valid email address = False 
email 'myemail@example.com' is valid email address = False

As you can see, 'myemail@example.com' is a valid email address, so why is it not valid when using isValidEmail? The rest of the unsub code errors out as well since I cannot use the "invalid" @subKey and @email strings.

When I statically set the variables (e.g. SET @subKey = "myemail@example.com" and SET @email= "myemail@example.com") instead of using the decrypted values, the rest of the script works. Is DecryptSymmetric not returning the same characters as is displayed when using %%=v(@subKey)=%% and %%=v(@email)=%%?

Any help will be greatly appreciated. Thanks!

  • Could you insert a Length() call on the before encryption string, and then after? I'm wondering if there are hidden characters. – Timothy Jun 4 '14 at 20:09
  • Great idea, thanks! After running a JavaScript alert() on the strings, I found that there were special characters appended to them that the browser did not display. So using RegExMatch(@email, "[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}", 0, "IgnoreCase", "Multiline") I was able to pull the valid email and everything worked. A Replace(Replace(Replace(@email, "+", "-"), "/", "_"), "=", ",") is used before passing the encrypted values to make it parameter-safe and then the reverse as shown in the above code to get the original encrypted value, so the special characters could be coming from there? – Ellen Jun 5 '14 at 13:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.