1 | <?php |
||
7 | class Encryption |
||
8 | { |
||
9 | |||
10 | /** |
||
11 | * Cipher algorithm |
||
12 | * |
||
13 | * @var string |
||
14 | */ |
||
15 | const CIPHER = 'aes-256-cbc'; |
||
16 | |||
17 | /** |
||
18 | * Hash function |
||
19 | * |
||
20 | * @var string |
||
21 | */ |
||
22 | const HASH_FUNCTION = 'sha256'; |
||
23 | |||
24 | /** |
||
25 | * constructor for Encryption object. |
||
26 | * |
||
27 | * @access private |
||
28 | */ |
||
29 | private function __construct() |
||
32 | |||
33 | /** |
||
34 | * Encrypt a string. |
||
35 | * |
||
36 | * @access public |
||
37 | * @static static method |
||
38 | * @param string $plain |
||
39 | * @return string |
||
40 | * @throws Exception If functions don't exists |
||
41 | */ |
||
42 | public static function encrypt($plain) |
||
69 | |||
70 | /** |
||
71 | * Decrypted a string. |
||
72 | * |
||
73 | * @access public |
||
74 | * @static static method |
||
75 | * @param string $ciphertext |
||
76 | * @return string |
||
77 | * @throws Exception If $ciphertext is empty, or If functions don't exists |
||
78 | */ |
||
79 | public static function decrypt($ciphertext) |
||
112 | |||
113 | /** |
||
114 | * A timing attack resistant comparison. |
||
115 | * |
||
116 | * @access private |
||
117 | * @static static method |
||
118 | * @param string $hmac The hmac from the ciphertext being decrypted. |
||
119 | * @param string $compare The comparison hmac. |
||
120 | * @return bool |
||
121 | * @see https://github.com/sarciszewski/php-future/blob/bd6c91fb924b2b35a3e4f4074a642868bd051baf/src/Security.php#L36 |
||
122 | */ |
||
123 | private static function hashEquals($hmac, $compare) |
||
146 | } |
||
147 |