PHP converted to CF
i trying convert php coldfusion, not sure of doing... ^ operator. 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 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 far:
<cfscript>
account_key = "whoisit28";
api_key = "12345";
salted = api_key & account_key;
hashed = tobase64(hash(salted,'sha'));
saltedhash = left(hashed,16);
iv = "openssl ruby";
/*iv = arraynew(1);
for(i=1; lte len(iv_list);i++){
iv[i] = 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 guid, '#expires#' expires, firstname + ' ' + lastname display_name, email, 'http://www.mastercontrolcustomers.com' url, '' avatar_url
contacts
contactid = #contactid#
</cfquery>
<cfset data = serializejson(user)>
<cfscript>
for(i=1; lte 16; i++){
tmp1 = mid(iv,i,1);
tmp2 = mid(data,i,1);
}
</cfscript>
the code seem encrypt json data aes (formerly known as
rijndael). ^ operator bit-wise operator , what
the comment above says: xor.
mack
More discussions in ColdFusion
adobe
Comments
Post a Comment