/** * the construtor,the param $path is the keys saving path */ public function __construct($path) { if(empty($path) || !is_dir($path)){ throw new Exception('Must set the keys save path'); }
$this- _keyPath = $path; }
/** * create the key pair,save the key to $this- _keyPath */ public function createKey() { $r = openssl_pkey_new(); openssl_pkey_export($r, $privKey); file_put_contents($this- _keyPath . DIRECTORY_SEPARATOR . 'priv.key', $privKey); $this- _privKey = openssl_pkey_get_public($privKey);