1 | <?php |
||
17 | final class RSA |
||
18 | { |
||
19 | /** |
||
20 | * Integer-to-Octet-String primitive. |
||
21 | * |
||
22 | * @param \Jose\Util\BigInteger $x |
||
23 | * @param int $xLen |
||
24 | * |
||
25 | * @return string |
||
26 | */ |
||
27 | private static function convertIntegerToOctetString($x, $xLen) |
||
36 | |||
37 | /** |
||
38 | * Octet-String-to-Integer primitive. |
||
39 | * |
||
40 | * @param string $x |
||
41 | * |
||
42 | * @return \Jose\Util\BigInteger |
||
43 | */ |
||
44 | private static function convertOctetStringToInteger($x) |
||
48 | |||
49 | /** |
||
50 | * Exponentiate with or without Chinese Remainder Theorem. |
||
51 | * |
||
52 | * @param \Jose\KeyConverter\RSAKey $key |
||
53 | * @param \Jose\Util\BigInteger $x |
||
54 | * |
||
55 | * @return \Jose\Util\BigInteger |
||
56 | */ |
||
57 | private static function _exponentiate(RSAKey $key, $x) |
||
61 | |||
62 | /** |
||
63 | * RSAEP. |
||
64 | * |
||
65 | * @param \Jose\KeyConverter\RSAKey $key |
||
66 | * @param \Jose\Util\BigInteger $m |
||
67 | * |
||
68 | * @return \Jose\Util\BigInteger|false |
||
69 | */ |
||
70 | private static function _rsaep(RSAKey $key, BigInteger $m) |
||
78 | |||
79 | /** |
||
80 | * RSADP. |
||
81 | * |
||
82 | * @param \Jose\KeyConverter\RSAKey $key |
||
83 | * @param \Jose\Util\BigInteger $c |
||
84 | * |
||
85 | * @return \Jose\Util\BigInteger|false |
||
86 | */ |
||
87 | private static function _rsadp(RSAKey $key, BigInteger $c) |
||
95 | |||
96 | /** |
||
97 | * RSASP1. |
||
98 | * |
||
99 | * @param \Jose\KeyConverter\RSAKey $key |
||
100 | * @param \Jose\Util\BigInteger $m |
||
101 | * |
||
102 | * @return \Jose\Util\BigInteger|false |
||
103 | */ |
||
104 | private static function _rsasp1(RSAKey $key, BigInteger $m) |
||
112 | |||
113 | /** |
||
114 | * RSAVP1. |
||
115 | * |
||
116 | * @param \Jose\KeyConverter\RSAKey $key |
||
117 | * @param \Jose\Util\BigInteger $s |
||
118 | * |
||
119 | * @return \Jose\Util\BigInteger|false |
||
120 | */ |
||
121 | private static function _rsavp1(RSAKey $key, BigInteger $s) |
||
129 | |||
130 | /** |
||
131 | * MGF1. |
||
132 | * |
||
133 | * @param string $mgfSeed |
||
134 | * @param int $maskLen |
||
135 | * @param \Jose\Util\Hash $mgfHash |
||
136 | * |
||
137 | * @return string |
||
138 | */ |
||
139 | private static function _mgf1($mgfSeed, $maskLen, Hash $mgfHash) |
||
150 | |||
151 | /** |
||
152 | * RSAES-OAEP-ENCRYPT. |
||
153 | * |
||
154 | * @param \Jose\KeyConverter\RSAKey $key |
||
155 | * @param string $m |
||
156 | * @param \Jose\Util\Hash $hash |
||
157 | * |
||
158 | * @return string |
||
159 | */ |
||
160 | private static function _rsaes_oaep_encrypt(RSAKey $key, $m, Hash $hash) |
||
179 | |||
180 | /** |
||
181 | * RSAES-OAEP-DECRYPT. |
||
182 | * |
||
183 | * @param \Jose\KeyConverter\RSAKey $key |
||
184 | * @param string $c |
||
185 | * @param \Jose\Util\Hash $hash |
||
186 | * |
||
187 | * @return string |
||
188 | */ |
||
189 | private static function _rsaes_oaep_decrypt(RSAKey $key, $c, Hash $hash) |
||
216 | |||
217 | /** |
||
218 | * EMSA-PSS-ENCODE. |
||
219 | * |
||
220 | * @param string $m |
||
221 | * @param int $emBits |
||
222 | * @param \Jose\Util\Hash $hash |
||
223 | * |
||
224 | * @return string|bool |
||
225 | */ |
||
226 | private static function _emsa_pss_encode($m, $emBits, Hash $hash) |
||
251 | |||
252 | /** |
||
253 | * EMSA-PSS-VERIFY. |
||
254 | * |
||
255 | * @param string $m |
||
256 | * @param string $em |
||
257 | * @param int $emBits |
||
258 | * @param \Jose\Util\Hash $hash |
||
259 | * |
||
260 | * @return string |
||
261 | */ |
||
262 | private static function _emsa_pss_verify($m, $em, $emBits, Hash $hash) |
||
298 | |||
299 | /** |
||
300 | * Encryption. |
||
301 | * |
||
302 | * @param \Jose\KeyConverter\RSAKey $key |
||
303 | * @param string $plaintext |
||
304 | * @param string $hash_algorithm |
||
305 | * |
||
306 | * @return string |
||
307 | */ |
||
308 | public static function encrypt(RSAKey $key, $plaintext, $hash_algorithm) |
||
323 | |||
324 | /** |
||
325 | * Decryption. |
||
326 | * |
||
327 | * @param \Jose\KeyConverter\RSAKey $key |
||
328 | * @param string $ciphertext |
||
329 | * @param string $hash_algorithm |
||
330 | * |
||
331 | * @return string |
||
332 | */ |
||
333 | public static function decrypt(RSAKey $key, $ciphertext, $hash_algorithm) |
||
354 | |||
355 | /** |
||
356 | * Create a signature. |
||
357 | * |
||
358 | * @param \Jose\KeyConverter\RSAKey $key |
||
359 | * @param string $message |
||
360 | * @param string $hash |
||
361 | * |
||
362 | * @return string |
||
363 | */ |
||
364 | public static function sign(RSAKey $key, $message, $hash) |
||
383 | |||
384 | /** |
||
385 | * Verifies a signature. |
||
386 | * |
||
387 | * @param \Jose\KeyConverter\RSAKey $key |
||
388 | * @param string $message |
||
389 | * @param string $signature |
||
390 | * @param string $hash |
||
391 | * |
||
392 | * @return bool |
||
393 | */ |
||
394 | public static function verify(RSAKey $key, $message, $signature, $hash) |
||
413 | } |
||
414 |