1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* (c) Copyright Ascensio System SIA 2021 |
5
|
|
|
* |
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
7
|
|
|
* you may not use this file except in compliance with the License. |
8
|
|
|
* You may obtain a copy of the License at |
9
|
|
|
* |
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
11
|
|
|
* |
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15
|
|
|
* See the License for the specific language governing permissions and |
16
|
|
|
* limitations under the License. |
17
|
|
|
* |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
require_once __DIR__ . "/../../../main/inc/global.inc.php"; |
21
|
|
|
|
22
|
|
|
class Crypt { |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Generate token for the object |
26
|
|
|
* |
27
|
|
|
* @param array $object - object to signature |
28
|
|
|
* |
29
|
|
|
* @return string |
30
|
|
|
*/ |
31
|
|
|
public static function GetHash($object) |
32
|
|
|
{ |
33
|
|
|
return \Firebase\JWT\JWT::encode($object, api_get_security_key()); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Create an object from the token |
38
|
|
|
* |
39
|
|
|
* @param string $token - token |
40
|
|
|
* |
41
|
|
|
* @return array |
42
|
|
|
*/ |
43
|
|
|
public static function ReadHash($token) |
44
|
|
|
{ |
45
|
|
|
$result = null; |
46
|
|
|
$error = null; |
47
|
|
|
if ($token === null) { |
48
|
|
|
return [$result, "token is empty"]; |
49
|
|
|
} |
50
|
|
|
try { |
51
|
|
|
$result = \Firebase\JWT\JWT::decode($token, api_get_security_key(), array("HS256")); |
52
|
|
|
} catch (\UnexpectedValueException $e) { |
53
|
|
|
$error = $e->getMessage(); |
54
|
|
|
} |
55
|
|
|
return [$result, $error]; |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|