CryptRSA   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 10
c 0
b 0
f 0
dl 0
loc 21
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A generate() 0 16 2
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