This repository has been archived by the owner on Sep 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
decrypt.php
50 lines (47 loc) · 1.48 KB
/
decrypt.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
function decryptResponses($privateKey, $data, $handle)
{
$first = true;
foreach (explode('.', $data) as $encryptedResponse)
{
echo "Decrypting response...\n";
$decryptedKey = '';
$allData = base64_decode($encryptedResponse);
$encryptedKey = substr($allData, 0, 128);
if (openssl_private_decrypt($encryptedKey, $decryptedKey, $privateKey))
{
$iv = substr($encryptedKey, 0, mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_CBC));
$data = mcrypt_decrypt(MCRYPT_BLOWFISH, $decryptedKey, substr($allData, 128), MCRYPT_MODE_CBC, $iv);
$response = json_decode(trim($data), true);
if ($first)
{
fputcsv($handle, array_keys($response));
$first = false;
}
fputcsv($handle, $response);
unset($response);
}
else
{
echo openssl_error_string() . "\n";
}
}
}
$stdin = fopen('php://stdin', 'r');
if (isset($argv[1]))
{
$privateKey = openssl_pkey_get_private(file_get_contents($argv[1]));
}
else
{
echo "Please enter the path to the private key file: ";
$file = rtrim(fgets($stdin));
echo '"' . $file . '"' . PHP_EOL;
$key = file_get_contents($file);
$privateKey = openssl_pkey_get_private($key);
}
$handle = fopen('php://stdout', 'w');
/**
* The builder script will add the appropriate decrypt command to the end
* of the file. DO NOT ADD A CLOSING TAG.
*/