Skip to content

Commit d432ef9

Browse files
authored
Create RSA.php
1 parent 9eadc8c commit d432ef9

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/Utils/RSA.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace ZhenMu\Support\Utils;
4+
5+
class RSA
6+
{
7+
public static function generate($config = [])
8+
{
9+
$config = array_merge(array(
10+
'private_key_bits' => 2048,
11+
'private_key_type' => OPENSSL_KEYTYPE_RSA,
12+
), $config);
13+
14+
$privateKeyObj = openssl_pkey_new($config);
15+
16+
$publicKey = openssl_pkey_get_details($privateKeyObj)['key'];
17+
openssl_pkey_export($privateKeyObj, $privateKey);
18+
19+
return [
20+
'publicKey' => $publicKey,
21+
'privateKey' => $privateKey,
22+
];
23+
}
24+
}

0 commit comments

Comments
 (0)