CryptRSA::generate()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
c 0
b 0
f 0
dl 0
loc 16
rs 9.9666
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Rogierw\RwAcme\Support;
4
5
use Rogierw\RwAcme\Exceptions\LetsEncryptClientException;
6
7
class CryptRSA
8
{
9
    /**
10
     * @return array{privateKey: string, publicKey: string}
11
     */
12
    public static function generate(): array
13
    {
14
        $pKey = openssl_pkey_new([
15
            'private_key_type' => OPENSSL_KEYTYPE_RSA,
16
            'private_key_bits' => 4096,
17
        ]);
18
19
        if (!openssl_pkey_export($pKey, $privateKey)) {
20
            throw new LetsEncryptClientException('RSA keypair export failed.');
21
        }
22
23
        $details = openssl_pkey_get_details($pKey);
24
25
        return [
26
            'privateKey' => $privateKey,
27
            'publicKey' => $details['key'],
28
        ];
29
    }
30
}
31