-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
58dde26
commit c36648a
Showing
12 changed files
with
241 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,6 @@ php: | |
|
||
- "7.0" | ||
- "5.6" | ||
- "5.5" | ||
- "5.4" | ||
- "hhvm" | ||
|
||
sudo: false | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
namespace ParagonIE\EasyRSA; | ||
|
||
use \phpseclib\Crypt\RSA; | ||
use \ParagonIE\EasyRSA\Exception\InvalidKeyException; | ||
|
||
class KeyPair | ||
{ | ||
private $privateKey; | ||
protected $publicKey; | ||
|
||
public function __construct(PrivateKey $privateKey, PublicKey $publicKey = null) | ||
{ | ||
$this->privateKey = $privateKey; | ||
if (!$publicKey) { | ||
$publicKey = $this->privateKey->getPublicKey(); | ||
} | ||
$this->publicKey = $publicKey; | ||
} | ||
|
||
/** | ||
* Generate a private/public RSA key pair | ||
* | ||
* @param int $size Key size | ||
* @param string $passphrase Optional - password-protected private key | ||
* | ||
* @return self | ||
* @throws InvalidKeyException | ||
*/ | ||
public static function generateKeyPair($size = 2048) | ||
{ | ||
if ($size < 2048) { | ||
throw new InvalidKeyException('Key size must be at least 2048 bits.'); | ||
} | ||
$rsa = new RSA(); | ||
$keypair = $rsa->createKey($size); | ||
return new KeyPair( | ||
new PrivateKey($keypair['privatekey']), | ||
new PublicKey($keypair['publickey']) | ||
); | ||
} | ||
|
||
/** | ||
* @return PublicKey | ||
*/ | ||
public function getPublicKey() | ||
{ | ||
return $this->publicKey; | ||
} | ||
|
||
/** | ||
* @return PrivateKey | ||
*/ | ||
public function getPrivateKey() | ||
{ | ||
return $this->privateKey; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
namespace ParagonIE\EasyRSA; | ||
|
||
|
||
class PrivateKey | ||
{ | ||
protected $keyMaterial = ''; | ||
|
||
/** | ||
* PrivateKey constructor. | ||
* @param $string | ||
*/ | ||
public function __construct($string) | ||
{ | ||
$this->keyMaterial = $string; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function __debugInfo() | ||
{ | ||
return []; | ||
} | ||
|
||
/** | ||
* return PublicKey | ||
*/ | ||
public function getPublicKey() | ||
{ | ||
$res = \openssl_pkey_get_private($this->keyMaterial); | ||
$pubkey = \openssl_pkey_get_details($res); | ||
$public = \rtrim( | ||
\str_replace("\n", "\r\n", $pubkey['key']), | ||
"\r\n" | ||
); | ||
return new PublicKey($public); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getKey() | ||
{ | ||
return $this->keyMaterial; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
namespace ParagonIE\EasyRSA; | ||
|
||
class PublicKey | ||
{ | ||
protected $keyMaterial = ''; | ||
|
||
/** | ||
* PrivateKey constructor. | ||
* @param $string | ||
*/ | ||
public function __construct($string) | ||
{ | ||
$this->keyMaterial = $string; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function __debugInfo() | ||
{ | ||
return []; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getKey() | ||
{ | ||
return $this->keyMaterial; | ||
} | ||
} |
Oops, something went wrong.