- hash_hmac: documentation ( source)
- base64_encode: documentation ( source)
<?php
$env = array(
'token' => 'generickey',
'brand' => 'conversant360',
'macMethod' => 'sha256',
'expire' => '+30 minutes',
'primaryURL' => 'https://new.qualtrics.com/ControlPanel/ssoTest.php?ssotoken=%s',
'secondaryURL' => 'https://new.qualtrics.com/ControlPanel/ssoTest.php?ssotoken=%s',
);
$token = "timestamp=2015-11-09T14:30:42&expiration=2015-11-09T14:30:42&id=a75f1ed5-dc40-e511-9990-005056bf0569&memberId=100353&firstName=John&lastName=Smith&email=john.smith@gmail.com&mac=54229f9a6d50f70454bb6c8331e4691bac2c809525b7481aa4f999e67eaa413d";
$hash = base64_encode( hash_hmac($env['macMethod'], $token, $env['token'], true) );
$token .= '&mac='.$hash;
//encrypt the token
$ivSize = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($ivSize, MCRYPT_RAND);
echo base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $env['token'], $token, MCRYPT_MODE_ECB,$iv));