1 | <?php |
||
23 | class JWKFactory |
||
24 | { |
||
25 | /** |
||
26 | * Creates a RSA key with the given key size and additional values. |
||
27 | * |
||
28 | * @param int $size The key size in bits |
||
29 | * @param array $values values to configure the key |
||
30 | * |
||
31 | * @return JWK |
||
32 | */ |
||
33 | public static function createRSAKey(int $size, array $values = []): JWK |
||
56 | |||
57 | /** |
||
58 | * Creates a EC key with the given curve and additional values. |
||
59 | * |
||
60 | * @param string $curve The curve |
||
61 | * @param array $values values to configure the key |
||
62 | * |
||
63 | * @return JWK |
||
64 | */ |
||
65 | public static function createECKey(string $curve, array $values = []): JWK |
||
76 | |||
77 | /** |
||
78 | * @param string $curve |
||
79 | * |
||
80 | * @return array |
||
81 | */ |
||
82 | private static function createECKeyUsingPurePhp(string $curve): array |
||
112 | |||
113 | /** |
||
114 | * @param string $curve |
||
115 | * |
||
116 | * @return array |
||
117 | */ |
||
118 | private static function createECKeyUsingOpenSSL(string $curve): array |
||
140 | |||
141 | /** |
||
142 | * @param string $curve |
||
143 | * |
||
144 | * @return string |
||
145 | */ |
||
146 | private static function getOpensslCurveName(string $curve): string |
||
159 | |||
160 | /** |
||
161 | * Creates a octet key with the given key size and additional values. |
||
162 | * |
||
163 | * @param int $size The key size in bits |
||
164 | * @param array $values values to configure the key |
||
165 | * |
||
166 | * @return JWK |
||
167 | */ |
||
168 | public static function createOctKey(int $size, array $values = []): JWK |
||
183 | |||
184 | /** |
||
185 | * Creates a OKP key with the given curve and additional values. |
||
186 | * |
||
187 | * @param string $curve The curve |
||
188 | * @param array $values values to configure the key |
||
189 | * |
||
190 | * @return JWK |
||
191 | */ |
||
192 | public static function createOKPKey(string $curve, array $values = []): JWK |
||
223 | |||
224 | /** |
||
225 | * Creates a none key with the given additional values. |
||
226 | * Please note that this key type is not pat of any specification. |
||
227 | * It is used to prevent the use of the "none" algorithm with other key types. |
||
228 | * |
||
229 | * @param array $values values to configure the key |
||
230 | * |
||
231 | * @return JWK |
||
232 | */ |
||
233 | public static function createNoneKey(array $values = []): JWK |
||
246 | |||
247 | /** |
||
248 | * Creates a key from a Json string. |
||
249 | * |
||
250 | * @param string $value |
||
251 | * |
||
252 | * @return JWK|JWKSet |
||
253 | */ |
||
254 | public static function createFromJsonObject(string $value) |
||
263 | |||
264 | /** |
||
265 | * Creates a key or key set from the given input. |
||
266 | * |
||
267 | * @param array $values |
||
268 | * |
||
269 | * @return JWK|JWKSet |
||
270 | */ |
||
271 | public static function createFromValues(array $values) |
||
279 | |||
280 | /** |
||
281 | * This method create a JWK object using a shared secret. |
||
282 | * |
||
283 | * @param string $secret |
||
284 | * @param array $additional_values |
||
285 | * |
||
286 | * @return JWK |
||
287 | */ |
||
288 | public static function createFromSecret(string $secret, array $additional_values = []): JWK |
||
300 | |||
301 | /** |
||
302 | * This method will try to load a X.509 certificate and convert it into a public key. |
||
303 | * |
||
304 | * @param string $file |
||
305 | * @param array $additional_values |
||
306 | * |
||
307 | * @return JWK |
||
308 | */ |
||
309 | public static function createFromCertificateFile(string $file, array $additional_values = []): JWK |
||
316 | |||
317 | /** |
||
318 | * Extract a keyfrom a key set identified by the given index . |
||
319 | * |
||
320 | * @param JWKSet $jwkset |
||
321 | * @param int|string $index |
||
322 | * |
||
323 | * @return JWK |
||
324 | */ |
||
325 | public static function createFromKeySet(JWKSet $jwkset, $index): JWK |
||
329 | |||
330 | /** |
||
331 | * This method will try to load a PKCS#12 file and convert it into a public key. |
||
332 | * |
||
333 | * @param string $file |
||
334 | * @param null|string $secret |
||
335 | * @param array $additional_values |
||
336 | * |
||
337 | * @throws \Exception |
||
338 | * |
||
339 | * @return JWK |
||
340 | */ |
||
341 | public static function createFromPKCS12CertificateFile(string $file, ?string $secret = '', array $additional_values = []): JWK |
||
350 | |||
351 | /** |
||
352 | * This method will try to convert a X.509 certificate into a public key. |
||
353 | * |
||
354 | * @param string $certificate |
||
355 | * @param array $additional_values |
||
356 | * |
||
357 | * @return JWK |
||
358 | */ |
||
359 | public static function createFromCertificate(string $certificate, array $additional_values = []): JWK |
||
366 | |||
367 | /** |
||
368 | * This method will try to convert a X.509 certificate resource into a public key. |
||
369 | * |
||
370 | * @param resource $res |
||
371 | * @param array $additional_values |
||
372 | * |
||
373 | * @throws \Exception |
||
374 | * |
||
375 | * @return JWK |
||
376 | */ |
||
377 | public static function createFromX509Resource($res, array $additional_values = []): JWK |
||
384 | |||
385 | /** |
||
386 | * This method will try to load and convert a key file into a JWK object. |
||
387 | * If the key is encrypted, the password must be set. |
||
388 | * |
||
389 | * @param string $file |
||
390 | * @param null|string $password |
||
391 | * @param array $additional_values |
||
392 | * |
||
393 | * @throws \Exception |
||
394 | * |
||
395 | * @return JWK |
||
396 | */ |
||
397 | public static function createFromKeyFile(string $file, ?string $password = null, array $additional_values = []): JWK |
||
404 | |||
405 | /** |
||
406 | * This method will try to load and convert a key into a JWK object. |
||
407 | * If the key is encrypted, the password must be set. |
||
408 | * |
||
409 | * @param string $key |
||
410 | * @param null|string $password |
||
411 | * @param array $additional_values |
||
412 | * |
||
413 | * @throws \Exception |
||
414 | * |
||
415 | * @return JWK |
||
416 | */ |
||
417 | public static function createFromKey(string $key, ?string $password = null, array $additional_values = []): JWK |
||
424 | |||
425 | /** |
||
426 | * This method will try to load and convert a X.509 certificate chain into a public key. |
||
427 | * |
||
428 | * @param array $x5c |
||
429 | * @param array $additional_values |
||
430 | * |
||
431 | * @return JWK |
||
432 | */ |
||
433 | public static function createFromX5C(array $x5c, array $additional_values = []): JWK |
||
440 | } |
||
441 |