1 | <?php |
||
26 | class JWKFactory |
||
27 | { |
||
28 | /** |
||
29 | * Creates a RSA key with the given key size and additional values. |
||
30 | * |
||
31 | * @param int $size The key size in bits |
||
32 | * @param array $values values to configure the key |
||
33 | * |
||
34 | * @throws InvalidArgumentException if the key has an invalid size |
||
35 | * @throws InvalidArgumentException if it is not possible to create the key |
||
36 | */ |
||
37 | public static function createRSAKey(int $size, array $values = []): JWK |
||
63 | |||
64 | /** |
||
65 | * Creates a EC key with the given curve and additional values. |
||
66 | * |
||
67 | * @param string $curve The curve |
||
68 | * @param array $values values to configure the key |
||
69 | */ |
||
70 | public static function createECKey(string $curve, array $values = []): JWK |
||
74 | |||
75 | /** |
||
76 | * Creates a octet key with the given key size and additional values. |
||
77 | * |
||
78 | * @param int $size The key size in bits |
||
79 | * @param array $values values to configure the key |
||
80 | * |
||
81 | * @throws InvalidArgumentException if the key has an invalid size |
||
82 | */ |
||
83 | public static function createOctKey(int $size, array $values = []): JWK |
||
98 | |||
99 | /** |
||
100 | * Creates a OKP key with the given curve and additional values. |
||
101 | * |
||
102 | * @param string $curve The curve |
||
103 | * @param array $values values to configure the key |
||
104 | * |
||
105 | * @throws InvalidArgumentException if the extension "sobium" is not available |
||
106 | * @throws InvalidArgumentException if the curve is not supported |
||
107 | */ |
||
108 | public static function createOKPKey(string $curve, array $values = []): JWK |
||
144 | |||
145 | /** |
||
146 | * Creates a none key with the given additional values. |
||
147 | * Please note that this key type is not pat of any specification. |
||
148 | * It is used to prevent the use of the "none" algorithm with other key types. |
||
149 | * |
||
150 | * @param array $values values to configure the key |
||
151 | */ |
||
152 | public static function createNoneKey(array $values = []): JWK |
||
165 | |||
166 | /** |
||
167 | * Creates a key from a Json string. |
||
168 | * |
||
169 | * @throws InvalidArgumentException if the key or keyset is not valid |
||
170 | * |
||
171 | * @return JWK|JWKSet |
||
172 | */ |
||
173 | public static function createFromJsonObject(string $value) |
||
182 | |||
183 | /** |
||
184 | * Creates a key or key set from the given input. |
||
185 | * |
||
186 | * @return JWK|JWKSet |
||
187 | */ |
||
188 | public static function createFromValues(array $values) |
||
196 | |||
197 | /** |
||
198 | * This method create a JWK object using a shared secret. |
||
199 | */ |
||
200 | public static function createFromSecret(string $secret, array $additional_values = []): JWK |
||
212 | |||
213 | /** |
||
214 | * This method will try to load a X.509 certificate and convert it into a public key. |
||
215 | */ |
||
216 | public static function createFromCertificateFile(string $file, array $additional_values = []): JWK |
||
223 | |||
224 | /** |
||
225 | * Extract a keyfrom a key set identified by the given index . |
||
226 | * |
||
227 | * @param int|string $index |
||
228 | */ |
||
229 | public static function createFromKeySet(JWKSet $jwkset, $index): JWK |
||
233 | |||
234 | /** |
||
235 | * This method will try to load a PKCS#12 file and convert it into a public key. |
||
236 | * |
||
237 | * @throws InvalidArgumentException if the certificate cannot be loaded |
||
238 | */ |
||
239 | public static function createFromPKCS12CertificateFile(string $file, ?string $secret = '', array $additional_values = []): JWK |
||
252 | |||
253 | /** |
||
254 | * This method will try to convert a X.509 certificate into a public key. |
||
255 | */ |
||
256 | public static function createFromCertificate(string $certificate, array $additional_values = []): JWK |
||
263 | |||
264 | /** |
||
265 | * This method will try to convert a X.509 certificate resource into a public key. |
||
266 | * |
||
267 | * @param resource $res |
||
268 | */ |
||
269 | public static function createFromX509Resource($res, array $additional_values = []): JWK |
||
276 | |||
277 | /** |
||
278 | * This method will try to load and convert a key file into a JWK object. |
||
279 | * If the key is encrypted, the password must be set. |
||
280 | */ |
||
281 | public static function createFromKeyFile(string $file, ?string $password = null, array $additional_values = []): JWK |
||
288 | |||
289 | /** |
||
290 | * This method will try to load and convert a key into a JWK object. |
||
291 | * If the key is encrypted, the password must be set. |
||
292 | */ |
||
293 | public static function createFromKey(string $key, ?string $password = null, array $additional_values = []): JWK |
||
300 | |||
301 | /** |
||
302 | * This method will try to load and convert a X.509 certificate chain into a public key. |
||
303 | * |
||
304 | * Be careful! The certificate chain is loaded, but it is NOT VERIFIED by any mean! |
||
305 | * It is mandatory to verify the root CA or intermediate CA are trusted. |
||
306 | * If not done, it may lead to potential security issues. |
||
307 | */ |
||
308 | public static function createFromX5C(array $x5c, array $additional_values = []): JWK |
||
315 | } |
||
316 |