Conditions | 2 |
Paths | 2 |
Total Lines | 17 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
9 | public static function generate(string $directory): void |
||
10 | { |
||
11 | $res = openssl_pkey_new([ |
||
12 | 'private_key_type' => OPENSSL_KEYTYPE_RSA, |
||
13 | 'private_key_bits' => 4096, |
||
14 | ]); |
||
15 | |||
16 | if (!openssl_pkey_export($res, $privateKey)) { |
||
17 | throw new RuntimeException('RSA keypair export failed.'); |
||
18 | } |
||
19 | |||
20 | $details = openssl_pkey_get_details($res); |
||
21 | |||
22 | file_put_contents($directory . 'private.pem', $privateKey); |
||
23 | file_put_contents($directory . 'public.pem', $details['key']); |
||
24 | |||
25 | openssl_pkey_free($res); |
||
26 | } |
||
28 |