1 | <?php |
||
23 | final class RSACrypt |
||
24 | { |
||
25 | /** |
||
26 | * Optimal Asymmetric Encryption Padding (OAEP). |
||
27 | */ |
||
28 | public const ENCRYPTION_OAEP = 1; |
||
29 | |||
30 | /** |
||
31 | * Use PKCS#1 padding. |
||
32 | */ |
||
33 | public const ENCRYPTION_PKCS1 = 2; |
||
34 | |||
35 | /** |
||
36 | * @param RSAKey $key |
||
37 | * @param string $data |
||
38 | * @param int $mode |
||
39 | * @param null|string $hash |
||
40 | * |
||
41 | * @return string |
||
42 | */ |
||
43 | public static function encrypt(RSAKey $key, string $data, int $mode, ?string $hash = null): string |
||
54 | |||
55 | /** |
||
56 | * @param RSAKey $key |
||
57 | * @param string $plaintext |
||
58 | * @param int $mode |
||
59 | * @param null|string $hash |
||
60 | * |
||
61 | * @return string |
||
62 | */ |
||
63 | public static function decrypt(RSAKey $key, string $plaintext, int $mode, ?string $hash = null): string |
||
74 | |||
75 | /** |
||
76 | * @param RSAKey $key |
||
77 | * @param string $data |
||
78 | * |
||
79 | * @return string |
||
80 | */ |
||
81 | public static function encryptWithRSA15(RSAKey $key, string $data): string |
||
105 | |||
106 | /** |
||
107 | * @param RSAKey $key |
||
108 | * @param string $c |
||
109 | * |
||
110 | * @return string |
||
111 | */ |
||
112 | public static function decryptWithRSA15(RSAKey $key, string $c): string |
||
138 | |||
139 | /** |
||
140 | * Encryption. |
||
141 | * |
||
142 | * @param RSAKey $key |
||
143 | * @param string $plaintext |
||
144 | * @param string $hash_algorithm |
||
145 | * |
||
146 | * @return string |
||
147 | */ |
||
148 | public static function encryptWithRSAOAEP(RSAKey $key, string $plaintext, string $hash_algorithm): string |
||
164 | |||
165 | /** |
||
166 | * Decryption. |
||
167 | * |
||
168 | * @param RSAKey $key |
||
169 | * @param string $ciphertext |
||
170 | * @param string $hash_algorithm |
||
171 | * |
||
172 | * @return string |
||
173 | */ |
||
174 | public static function decryptWithRSAOAEP(RSAKey $key, string $ciphertext, string $hash_algorithm): string |
||
190 | |||
191 | /** |
||
192 | * @param BigInteger $x |
||
193 | * @param int $xLen |
||
194 | * |
||
195 | * @return string |
||
196 | */ |
||
197 | private static function convertIntegerToOctetString(BigInteger $x, int $xLen): string |
||
206 | |||
207 | /** |
||
208 | * Octet-String-to-Integer primitive. |
||
209 | * |
||
210 | * @param string $x |
||
211 | * |
||
212 | * @return BigInteger |
||
213 | */ |
||
214 | private static function convertOctetStringToInteger(string $x): BigInteger |
||
218 | |||
219 | /** |
||
220 | * RSA EP. |
||
221 | * |
||
222 | * @param RSAKey $key |
||
223 | * @param BigInteger $m |
||
224 | * |
||
225 | * @return BigInteger |
||
226 | */ |
||
227 | private static function getRSAEP(RSAKey $key, BigInteger $m): BigInteger |
||
235 | |||
236 | /** |
||
237 | * RSA DP. |
||
238 | * |
||
239 | * @param RSAKey $key |
||
240 | * @param BigInteger $c |
||
241 | * |
||
242 | * @return BigInteger |
||
243 | */ |
||
244 | private static function getRSADP(RSAKey $key, BigInteger $c): BigInteger |
||
252 | |||
253 | /** |
||
254 | * MGF1. |
||
255 | * |
||
256 | * @param string $mgfSeed |
||
257 | * @param int $maskLen |
||
258 | * @param Hash $mgfHash |
||
259 | * |
||
260 | * @return string |
||
261 | */ |
||
262 | private static function getMGF1(string $mgfSeed, int $maskLen, Hash $mgfHash): string |
||
273 | |||
274 | /** |
||
275 | * RSAES-OAEP-ENCRYPT. |
||
276 | * |
||
277 | * @param RSAKey $key |
||
278 | * @param string $m |
||
279 | * @param Hash $hash |
||
280 | * |
||
281 | * @return string |
||
282 | */ |
||
283 | private static function encryptRSAESOAEP(RSAKey $key, string $m, Hash $hash): string |
||
302 | |||
303 | /** |
||
304 | * RSAES-OAEP-DECRYPT. |
||
305 | * |
||
306 | * @param RSAKey $key |
||
307 | * @param string $c |
||
308 | * @param Hash $hash |
||
309 | * |
||
310 | * @return string |
||
311 | */ |
||
312 | private static function getRSAESOAEP(RSAKey $key, string $c, Hash $hash): string |
||
336 | } |
||
337 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: