-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrsa.php
49 lines (35 loc) · 997 Bytes
/
rsa.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
defined( 'ABSPATH' ) or die();
class CacwpssaoKey {
private $rsa_path;
private $priv_key;
private $pub_key;
public function __construct() {
$this->rsa_path = CACWPSSAO_DIR_PATH . 'rsa/';
if( !( file_exists( $this->rsa_path . 'prkey.rsa' ) ) ) {
$this->genKeyPair();
}
$this->priv_key = $this->rsa_path . 'prkey.rsa';
$this->pub_key = $this->rsa_path . 'prkey.rsa.pub';
}
public function paths() {
$paths = array(
'private' => $this->priv_key,
'public' => $this->pub_key
);
return $paths;
}
private function genKeyPair() {
if( file_exists( $this->rsa_path . 'prkey.rsa.pub' ) ) {
unlink( $this->rsa_path . 'prkey.rsa.pub' );
}
$key = fopen( $this->rsa_path . 'prkey.rsa', 'w' );
$pkey = fopen( $this->rsa_path . 'prkey.rsa.pub', 'w' );
$rsa = new phpseclib\Crypt\RSA();
$keys = $rsa->createKey();
fwrite( $key, $keys['privatekey'] );
fwrite( $pkey, $keys['publickey'] );
fclose( $key );
fclose( $pkey );
}
}