|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the O2System Framework package. |
|
4
|
|
|
* |
|
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
6
|
|
|
* file that was distributed with this source code. |
|
7
|
|
|
* |
|
8
|
|
|
* @author Steeve Andrian Salim |
|
9
|
|
|
* @copyright Copyright (c) Steeve Andrian Salim |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
// ------------------------------------------------------------------------ |
|
13
|
|
|
|
|
14
|
|
|
namespace O2System\Security\Encryptions; |
|
15
|
|
|
|
|
16
|
|
|
// ------------------------------------------------------------------------ |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Class Algorithm |
|
20
|
|
|
* @package O2System\Security\Encryptions |
|
21
|
|
|
*/ |
|
22
|
|
|
class Algorithm |
|
23
|
|
|
{ |
|
24
|
|
|
public static $supported = [ |
|
25
|
|
|
'HS1' => ['hash_hmac', 'sha1'], |
|
26
|
|
|
'HS256' => ['hash_hmac', 'sha256'], |
|
27
|
|
|
'HS512' => ['hash_hmac', 'sha512'], |
|
28
|
|
|
'HS384' => ['hash_hmac', 'sha384'], |
|
29
|
|
|
'HMAC-SHA1' => ['HMAC', 'sha1'], |
|
30
|
|
|
'HMAC-SHA256' => ['HMAC', 'sha256'], |
|
31
|
|
|
'HMAC-SHA512' => ['HMAC', 'sha512'], |
|
32
|
|
|
'HMAC-SHA384' => ['HMAC', 'sha384'], |
|
33
|
|
|
'RS1' => ['openssl', OPENSSL_ALGO_SHA1], |
|
34
|
|
|
'RS256' => ['openssl', OPENSSL_ALGO_SHA256], |
|
35
|
|
|
'RS384' => ['openssl', OPENSSL_ALGO_SHA384], |
|
36
|
|
|
'RS512' => ['openssl', OPENSSL_ALGO_SHA512], |
|
37
|
|
|
]; |
|
38
|
|
|
|
|
39
|
|
|
// ------------------------------------------------------------------------ |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Algorithm::validate |
|
43
|
|
|
* |
|
44
|
|
|
* Validate algorithm |
|
45
|
|
|
* |
|
46
|
|
|
* @param string $algorithm |
|
47
|
|
|
* |
|
48
|
|
|
* @return bool |
|
49
|
|
|
*/ |
|
50
|
|
|
public static function validate($algorithm) |
|
51
|
|
|
{ |
|
52
|
|
|
$algorithm = strtoupper($algorithm); |
|
53
|
|
|
|
|
54
|
|
|
return (bool)array_key_exists($algorithm, static::$supported); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
// ------------------------------------------------------------------------ |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Algorithm::map |
|
61
|
|
|
* |
|
62
|
|
|
* Gets algorithm map. |
|
63
|
|
|
* |
|
64
|
|
|
* @param string $algorithm |
|
65
|
|
|
* |
|
66
|
|
|
* @return array |
|
67
|
|
|
*/ |
|
68
|
|
|
public static function map($algorithm) |
|
69
|
|
|
{ |
|
70
|
|
|
return static::$supported[ $algorithm ]; |
|
71
|
|
|
} |
|
72
|
|
|
} |