1 | <?php |
||
23 | 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 |
||
135 | |||
136 | /** |
||
137 | * Encryption. |
||
138 | * |
||
139 | * @param RSAKey $key |
||
140 | * @param string $plaintext |
||
141 | * @param string $hash_algorithm |
||
142 | * |
||
143 | * @return string |
||
144 | */ |
||
145 | public static function encryptWithRSAOAEP(RSAKey $key, string $plaintext, string $hash_algorithm): string |
||
161 | |||
162 | /** |
||
163 | * Decryption. |
||
164 | * |
||
165 | * @param RSAKey $key |
||
166 | * @param string $ciphertext |
||
167 | * @param string $hash_algorithm |
||
168 | * |
||
169 | * @return string |
||
170 | */ |
||
171 | public static function decryptWithRSAOAEP(RSAKey $key, string $ciphertext, string $hash_algorithm): string |
||
187 | |||
188 | /** |
||
189 | * @param BigInteger $x |
||
190 | * @param int $xLen |
||
191 | * |
||
192 | * @return string |
||
193 | */ |
||
194 | private static function convertIntegerToOctetString(BigInteger $x, int $xLen): string |
||
203 | |||
204 | /** |
||
205 | * Octet-String-to-Integer primitive. |
||
206 | * |
||
207 | * @param string $x |
||
208 | * |
||
209 | * @return BigInteger |
||
210 | */ |
||
211 | private static function convertOctetStringToInteger(string $x): BigInteger |
||
215 | |||
216 | /** |
||
217 | * RSA EP. |
||
218 | * |
||
219 | * @param RSAKey $key |
||
220 | * @param BigInteger $m |
||
221 | * |
||
222 | * @return BigInteger |
||
223 | */ |
||
224 | private static function getRSAEP(RSAKey $key, BigInteger $m): BigInteger |
||
232 | |||
233 | /** |
||
234 | * RSA DP. |
||
235 | * |
||
236 | * @param RSAKey $key |
||
237 | * @param BigInteger $c |
||
238 | * |
||
239 | * @return BigInteger |
||
240 | */ |
||
241 | private static function getRSADP(RSAKey $key, BigInteger $c): BigInteger |
||
249 | |||
250 | /** |
||
251 | * MGF1. |
||
252 | * |
||
253 | * @param string $mgfSeed |
||
254 | * @param int $maskLen |
||
255 | * @param Hash $mgfHash |
||
256 | * |
||
257 | * @return string |
||
258 | */ |
||
259 | private static function getMGF1(string $mgfSeed, int $maskLen, Hash $mgfHash): string |
||
270 | |||
271 | /** |
||
272 | * RSAES-OAEP-ENCRYPT. |
||
273 | * |
||
274 | * @param RSAKey $key |
||
275 | * @param string $m |
||
276 | * @param Hash $hash |
||
277 | * |
||
278 | * @return string |
||
279 | */ |
||
280 | private static function encryptRSAESOAEP(RSAKey $key, string $m, Hash $hash): string |
||
299 | |||
300 | /** |
||
301 | * RSAES-OAEP-DECRYPT. |
||
302 | * |
||
303 | * @param RSAKey $key |
||
304 | * @param string $c |
||
305 | * @param Hash $hash |
||
306 | * |
||
307 | * @return string |
||
308 | */ |
||
309 | private static function getRSAESOAEP(RSAKey $key, string $c, Hash $hash): string |
||
333 | } |
||
334 |
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: