5

I read elsewhere in StackExchange that it's not possible to decrypt AES strings originating from AMPScript in PHP. Is this true? It seems that it should be possible with mcrypt.

Also, part two for this question... if AES isn't possible, then should we go with DES or TripleDES? We need to be able to decrypt data generated in ExactTarget's EncryptSymmetric() function in a clients's PHP environment.

  • This is on topic as it pertains to ExactTarget. – Kelly J Andrews Jun 4 '14 at 22:24
  • @those who vote to close, can you at least leave a comment ? – Samuel De Rycke Jun 7 '14 at 16:48
  • any luck with this? – dchayka Mar 14 '16 at 16:38
2

I had the same question and thanks to the great work of @Kolohe with the mcrypt example I found a solution with openssl_decrypt and DES encryption.

With the upgrade to php7 we replaced mcrypt with openssl. So mcrypt wasn't a solution for us.

Because we pass the encrypted string as GET parameter it is wrapped with base64.

That's the AMPScript:

%%[
set @email = 'gone@world.com'
set @email_code = Base64Encode(EncryptSymmetric(@email, "des;mode=ecb;padding=zeros", @null, 'ab12cd34'))
Output(Concat(@email, '<br>'))
Output(Concat(@email_code, '<br>'))
]%%

That's the result from the AMPScript:

gone@world.com
TklMUTk4UjBhVlRWeXdDWHJCYk92Zz09

That's the PHP part:

$crypted = 'TklMUTk4UjBhVlRWeXdDWHJCYk92Zz09';
$crypted = base64_decode($crypted);
var_dump($crypted);
$decrypted = openssl_decrypt($crypted, 'des-ecb', 'ab12cd34', OPENSSL_ZERO_PADDING, '');
var_dump($decrypted);
$decrypted = trim($decrypted);
var_dump($decrypted);

And the PHP result:

string(24) "NILQ98R0aVTVywCXrBbOvg=="
string(16) "gone@world.com"
string(14) "gone@world.com"

The decrypted string has 2 control charactes at the end. I don't know why and in the end I wrapped it with a trim to solve the problem. It seems to work.

| improve this answer | |
1

I was able to get it to work with DES Still working on AES.

Use the example on the documentation for DES https://code.exacttarget.com/content-scripting/ampscript/encryption/EncryptSymmetric.html

Then use functions like like these

function decryptEtDES($key,$string)
{
    $string = base64_decode(str_replace(' ', "+", $string));
    $rtn = mcrypt_decrypt(MCRYPT_DES, $key, $string, MCRYPT_MODE_ECB);
    $rtn = rtrim($rtn, "\0\4");
    return($rtn);
}

function encryptEtDES($key,$string)
{
    $rtn = mcrypt_encrypt(MCRYPT_DES, $key, $string, MCRYPT_MODE_ECB);
    $rtn = base64_encode($rtn);
    return($rtn);
}
| improve this answer | |
0

Each individual algorithm is slightly unique between programming language, and ExactTarget's is based on C#.

In order to use PHP, you would need to recreate the algorithm that C# uses in PHP.

The simplest way to overcome this would be to create a landing page that uses AMPscript and pass the data to the page to be encrypted/decrypted.

| improve this answer | |
  • Thanks Kelly. What about just using DES instead, though? It's early enough in the process that we could try something like that. – James Jun 4 '14 at 22:30
  • I've not gotten it to work in any method, but this makes me want to attempt again just to make sure. – Kelly J Andrews Jun 4 '14 at 22:43
  • This page seems to give me some hope, but not able to reproduce from exact target yet. stackoverflow.com/questions/6130989/… – James Jun 6 '14 at 20:08
  • @KellyJAndrews were you able to create a PHP script to decrypt C#'s encryption from ExactTarget's side? – dchayka Mar 14 '16 at 16:54
  • @dchayka not successfully, no – Kelly J Andrews Mar 14 '16 at 17:15

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.