-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathencryptDecrypt.php
More file actions
46 lines (41 loc) · 1.79 KB
/
encryptDecrypt.php
File metadata and controls
46 lines (41 loc) · 1.79 KB
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
<?php
// An example of encrypting and decrypting your Token and accessing the API using PHP; specifically the getStudentsDetails method.
// Constants to use when generating API requests - change these as per your TASS API Gateway
$tokenKey = 'x8FWQUedjyiUGlTf5appPQ==';
$appCode = 'DEMOAPP';
$companyCode = '10';
$apiVersion = '2';
$method = 'getStudentsDetails';
$endPoint = 'https://api.tasscloud.com.au/tassweb/api/';
$parameters = '{"currentstatus":"current"}';
function Encrypt($tokenKey, $parameters) {
$decodedKey = base64_decode($tokenKey);
$encrypted = openssl_encrypt($parameters, 'aes-128-ecb', $decodedKey, OPENSSL_RAW_DATA);
$encoded = base64_encode($encrypted);
return $encoded;
}
function Decrypt($tokenKey, $s) {
$decodedKey = base64_decode($tokenKey);
$s = base64_decode($s);
$s = openssl_decrypt($s, 'aes-128-ecb', $decodedKey, OPENSSL_RAW_DATA);
return $s;
}
function getURLRequest($endPoint, $method, $appCode, $companyCode, $apiVersion, $parameters, $tokenKey) {
$encryptedToken = Encrypt($tokenKey, $parameters);
$dict = array('method' => $method, 'appcode' => $appCode, 'company' => $companyCode, 'v' => $apiVersion, 'token' => $encryptedToken);
$URLString = $endPoint . '?';
foreach($dict as $key => $value) {
$URLString .= $key;
$URLString .= '=';
$URLString .= urlencode($value);
$URLString .= '&';
}
// Trim the last ampersand because it's not necessary
$URLString = substr($URLString, 0, -1);
return $URLString;
}
echo 'Original: ', $parameters, PHP_EOL;
echo 'Encrypted: ', Encrypt($tokenKey, $parameters), PHP_EOL;
echo 'Decrypted: ', Decrypt($tokenKey, Encrypt($tokenKey, $parameters)), PHP_EOL;
echo 'URL: ', getURLRequest($endPoint, $method, $appCode, $companyCode, $apiVersion, $parameters, $tokenKey), PHP_EOL;
?>