-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathphp.php
36 lines (29 loc) · 986 Bytes
/
php.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
$account_key = "YOUR_ACCOUNT_KEY";
$api_key = "YOUR_API_KEY";
$salted = $api_key . $account_key;
$hash = hash('sha1',$salted,true);
$saltedHash = substr($hash,0,16);
$iv = "OpenSSL for Ruby";
$user_data = array(
"guid" => "<%= example_user[:guid] %>",
"expires" => "<%= example_user[:expires].to_s(:db) %>",
"display_name" => "<%= example_user[:display_name] %>",
"email" => "<%= example_user[:email] %>",
"url" => "<%= example_user[:url] %>",
"avatar_url" => "<%= example_user[:avatar_url] %>"
);
$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));
?>