PHP converted to CF
I am trying to convert this php to coldfusion, but I am not sure what some of it is doing... like the ^ operator. Any help would be super awesome
PHP:
<?php
$account_key = "whoisit28";
$api_key = "12345";
$salted = $api_key . $account_key;
$hash = hash('sha1',$salted,true);
$saltedHash = substr($hash,0,16);
$iv = "OpenSSL for Ruby";
$user_data = array(
"guid" => "1234",
"expires" => "2009-05-29 20:02:40",
"display_name" => "Richard White",
"email" => "rich@acme.com",
"url" => "http://acme.com/users/1234",
"avatar_url" => "http://acme.com/users/1234/avatar.png"
);
$data = json_encode($user_data);
// double XOR first block
for ($i = 0; $i < 16; $i++)
{
$data[$i] = $data[$i] ^ $iv[$i];
}
$pad = 16 - (strlen($data) % 16);
$data = $data . str_repeat(chr($pad), $pad);
$cipher = mcrypt_module_open(MCRYPT_RIJNDAEL_128,'','cbc','');
mcrypt_generic_init($cipher, $saltedHash, $iv);
$encryptedData = mcrypt_generic($cipher,$data);
mcrypt_generic_deinit($cipher);
$encryptedData = urlencode(base64_encode($encryptedData));
?>
My CF so far:
<cfscript>
account_key = "whoisit28";
api_key = "12345";
salted = api_key & account_key;
hashed = toBase64(hash(salted,'SHA'));
saltedHash = left(hashed,16);
iv = "OpenSSL for Ruby";
/*iv = arrayNew(1);
for(i=1; i lte len(iv_list);i++){
iv = mid(iv_list,i,1);
}*/
expires = dateadd("h",1,now());
expires = dateformat(expires,"yyyy-mm-dd") &" "& timeformat(expires,"HH:mm:ss");
</cfscript>
<cfquery name="user" datasource="datasource">
select contactid as guid, '#expires#' as expires, firstname + ' ' + lastname as display_name, email, 'http://www.mastercontrolcustomers.com' as url, '' as avatar_url
from contacts
where contactid = #contactid#
</cfquery>
<cfset data = serializeJSON(user)>
<cfscript>
for(i=1; i lte 16; i++){
tmp1 = mid(iv,i,1);
tmp2 = mid(data,i,1);
}
</cfscript>
