@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | /** |
24 | 24 | * @var array |
25 | 25 | */ |
26 | - private $info = []; |
|
26 | + private $info = []; |
|
27 | 27 | |
28 | 28 | /** |
29 | 29 | * @var X509|null |
@@ -35,11 +35,11 @@ discard block |
||
35 | 35 | */ |
36 | 36 | private $original_pem = null; |
37 | 37 | |
38 | - public function __construct($pem){ |
|
38 | + public function __construct($pem) { |
|
39 | 39 | |
40 | 40 | $this->file = new X509(); |
41 | 41 | $this->info = $this->file->loadX509($pem); |
42 | - if($this->info === false) throw new InvalidX509CertificateException($pem); |
|
42 | + if ($this->info === false) throw new InvalidX509CertificateException($pem); |
|
43 | 43 | $this->original_pem = $pem; |
44 | 44 | } |
45 | 45 | |
@@ -51,8 +51,8 @@ discard block |
||
51 | 51 | return $this->original_pem; |
52 | 52 | } |
53 | 53 | |
54 | - private function calculateThumbprint($alg){ |
|
55 | - $pem = str_replace( array("\n","\r"), '', trim($this->original_pem)); |
|
54 | + private function calculateThumbprint($alg) { |
|
55 | + $pem = str_replace(array("\n", "\r"), '', trim($this->original_pem)); |
|
56 | 56 | return strtoupper(hash($alg, base64_decode($pem))); |
57 | 57 | } |
58 | 58 | |
@@ -78,9 +78,9 @@ discard block |
||
78 | 78 | public function getPublicKey() |
79 | 79 | { |
80 | 80 | $pem = (string)$this->file->getPublicKey(); |
81 | - $pem = preg_replace('/\-+BEGIN PUBLIC KEY\-+/','',$pem); |
|
82 | - $pem = preg_replace('/\-+END PUBLIC KEY\-+/','',$pem); |
|
83 | - $pem = str_replace( array("\n","\r","\t"), '', trim($pem)); |
|
81 | + $pem = preg_replace('/\-+BEGIN PUBLIC KEY\-+/', '', $pem); |
|
82 | + $pem = preg_replace('/\-+END PUBLIC KEY\-+/', '', $pem); |
|
83 | + $pem = str_replace(array("\n", "\r", "\t"), '', trim($pem)); |
|
84 | 84 | return $pem; |
85 | 85 | } |
86 | 86 |
@@ -39,7 +39,9 @@ |
||
39 | 39 | |
40 | 40 | $this->file = new X509(); |
41 | 41 | $this->info = $this->file->loadX509($pem); |
42 | - if($this->info === false) throw new InvalidX509CertificateException($pem); |
|
42 | + if($this->info === false) { |
|
43 | + throw new InvalidX509CertificateException($pem); |
|
44 | + } |
|
43 | 45 | $this->original_pem = $pem; |
44 | 46 | } |
45 | 47 |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | * @param PublicKey $public_key |
33 | 33 | * @param PrivateKey $private_key |
34 | 34 | */ |
35 | - public function __construct(PublicKey $public_key, PrivateKey $private_key){ |
|
35 | + public function __construct(PublicKey $public_key, PrivateKey $private_key) { |
|
36 | 36 | |
37 | 37 | $this->private_key = $private_key; |
38 | 38 | $this->public_key = $public_key; |
@@ -41,11 +41,11 @@ discard block |
||
41 | 41 | /** |
42 | 42 | * @return PublicKey |
43 | 43 | */ |
44 | - public function getPublic(){ return $this->public_key; } |
|
44 | + public function getPublic() { return $this->public_key; } |
|
45 | 45 | |
46 | 46 | /** |
47 | 47 | * @return PrivateKey |
48 | 48 | */ |
49 | - public function getPrivate(){ return $this->private_key; } |
|
49 | + public function getPrivate() { return $this->private_key; } |
|
50 | 50 | |
51 | 51 | } |
52 | 52 | \ No newline at end of file |
@@ -40,17 +40,17 @@ |
||
40 | 40 | * @param string $password |
41 | 41 | * @throws RSABadPEMFormat |
42 | 42 | */ |
43 | - public function __construct($pem_format, $password = null){ |
|
43 | + public function __construct($pem_format, $password = null) { |
|
44 | 44 | |
45 | 45 | $this->pem_format = $pem_format; |
46 | 46 | $this->rsa_imp = new RSA(); |
47 | 47 | |
48 | - if(!empty($password)) |
|
48 | + if (!empty($password)) |
|
49 | 49 | $this->rsa_imp->setPassword($password); |
50 | 50 | |
51 | 51 | $res = $this->rsa_imp->loadKey($this->pem_format, RSA::PRIVATE_FORMAT_PKCS1); |
52 | 52 | |
53 | - if(!$res) throw new RSABadPEMFormat(sprintf('pem %s',$pem_format )); |
|
53 | + if (!$res) throw new RSABadPEMFormat(sprintf('pem %s', $pem_format)); |
|
54 | 54 | |
55 | 55 | $this->n = $this->rsa_imp->modulus; |
56 | 56 | } |
@@ -45,12 +45,15 @@ |
||
45 | 45 | $this->pem_format = $pem_format; |
46 | 46 | $this->rsa_imp = new RSA(); |
47 | 47 | |
48 | - if(!empty($password)) |
|
49 | - $this->rsa_imp->setPassword($password); |
|
48 | + if(!empty($password)) { |
|
49 | + $this->rsa_imp->setPassword($password); |
|
50 | + } |
|
50 | 51 | |
51 | 52 | $res = $this->rsa_imp->loadKey($this->pem_format, RSA::PRIVATE_FORMAT_PKCS1); |
52 | 53 | |
53 | - if(!$res) throw new RSABadPEMFormat(sprintf('pem %s',$pem_format )); |
|
54 | + if(!$res) { |
|
55 | + throw new RSABadPEMFormat(sprintf('pem %s',$pem_format )); |
|
56 | + } |
|
54 | 57 | |
55 | 58 | $this->n = $this->rsa_imp->modulus; |
56 | 59 | } |
@@ -32,11 +32,11 @@ discard block |
||
32 | 32 | * @param string $password |
33 | 33 | * @throws RSABadPEMFormat |
34 | 34 | */ |
35 | - public function __construct($pem_format, $password = null){ |
|
35 | + public function __construct($pem_format, $password = null) { |
|
36 | 36 | |
37 | 37 | parent::__construct($pem_format, $password); |
38 | 38 | $this->d = $this->rsa_imp->exponent; |
39 | - if($this->d->toString() === $this->e->toString()) |
|
39 | + if ($this->d->toString() === $this->e->toString()) |
|
40 | 40 | throw new RSABadPEMFormat(sprintf('pem %s is a public key!', $pem_format)); |
41 | 41 | } |
42 | 42 | |
@@ -56,9 +56,9 @@ discard block |
||
56 | 56 | public function getEncoded() |
57 | 57 | { |
58 | 58 | $pem = $this->rsa_imp->getPrivateKey(RSA::PUBLIC_FORMAT_PKCS1); |
59 | - $pem = preg_replace('/\-+BEGIN RSA PRIVATE KEY\-+/','',$pem); |
|
60 | - $pem = preg_replace('/\-+END RSA PRIVATE KEY\-+/','',$pem); |
|
61 | - $pem = str_replace( array("\n","\r","\t"), '', trim($pem)); |
|
59 | + $pem = preg_replace('/\-+BEGIN RSA PRIVATE KEY\-+/', '', $pem); |
|
60 | + $pem = preg_replace('/\-+END RSA PRIVATE KEY\-+/', '', $pem); |
|
61 | + $pem = str_replace(array("\n", "\r", "\t"), '', trim($pem)); |
|
62 | 62 | return $pem; |
63 | 63 | } |
64 | 64 |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | * @param string $password |
33 | 33 | * @throws RSABadPEMFormat |
34 | 34 | */ |
35 | - public function __construct($pem_format, $password = null){ |
|
35 | + public function __construct($pem_format, $password = null) { |
|
36 | 36 | parent::__construct($pem_format, $password); |
37 | 37 | $this->e = $this->rsa_imp->publicExponent; |
38 | 38 | } |
@@ -60,9 +60,9 @@ discard block |
||
60 | 60 | public function getEncoded() |
61 | 61 | { |
62 | 62 | $pem = $this->rsa_imp->getPublicKey(RSA::PUBLIC_FORMAT_PKCS8); |
63 | - $pem = preg_replace('/\-+BEGIN PUBLIC KEY\-+/','',$pem); |
|
64 | - $pem = preg_replace('/\-+END PUBLIC KEY\-+/','',$pem); |
|
65 | - $pem = str_replace( array("\n","\r","\t"), '', trim($pem)); |
|
63 | + $pem = preg_replace('/\-+BEGIN PUBLIC KEY\-+/', '', $pem); |
|
64 | + $pem = preg_replace('/\-+END PUBLIC KEY\-+/', '', $pem); |
|
65 | + $pem = str_replace(array("\n", "\r", "\t"), '', trim($pem)); |
|
66 | 66 | return $pem; |
67 | 67 | } |
68 | 68 |
@@ -31,17 +31,17 @@ discard block |
||
31 | 31 | */ |
32 | 32 | private $rsa_imp; |
33 | 33 | |
34 | - private function __construct(){ |
|
34 | + private function __construct() { |
|
35 | 35 | $this->rsa_imp = new RSA(); |
36 | 36 | } |
37 | 37 | |
38 | - private function __clone(){} |
|
38 | + private function __clone() {} |
|
39 | 39 | |
40 | 40 | /** |
41 | 41 | * @return RSAFacade |
42 | 42 | */ |
43 | - public static function getInstance(){ |
|
44 | - if(!is_object(self::$instance)){ |
|
43 | + public static function getInstance() { |
|
44 | + if (!is_object(self::$instance)) { |
|
45 | 45 | self::$instance = new RSAFacade(); |
46 | 46 | } |
47 | 47 | return self::$instance; |
@@ -51,12 +51,12 @@ discard block |
||
51 | 51 | * @param $bits |
52 | 52 | * @return KeyPair |
53 | 53 | */ |
54 | - public function buildKeyPair($bits){ |
|
54 | + public function buildKeyPair($bits) { |
|
55 | 55 | $this->rsa_imp->setPrivateKeyFormat(RSA::PRIVATE_FORMAT_PKCS1); |
56 | 56 | $this->rsa_imp->setPublicKeyFormat(RSA::PUBLIC_FORMAT_PKCS1); |
57 | 57 | |
58 | 58 | $list = $this->rsa_imp->createKey($bits); |
59 | - return new KeyPair( new _RSAPublicKeyPEMFornat($list['publickey']), new _RSAPrivateKeyPEMFornat($list['privatekey'])); |
|
59 | + return new KeyPair(new _RSAPublicKeyPEMFornat($list['publickey']), new _RSAPrivateKeyPEMFornat($list['privatekey'])); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | * @param BigInteger $e |
65 | 65 | * @return RSAPublicKey |
66 | 66 | */ |
67 | - public function buildPublicKey(BigInteger $n, BigInteger $e){ |
|
67 | + public function buildPublicKey(BigInteger $n, BigInteger $e) { |
|
68 | 68 | $public_key_pem = $this->rsa_imp->_convertPublicKey($n, $e); |
69 | 69 | return new _RSAPublicKeyPEMFornat($public_key_pem); |
70 | 70 | } |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | * @param \Math_BigInteger $d |
75 | 75 | * @return RSAPrivateKey |
76 | 76 | */ |
77 | - public function buildMinimalPrivateKey(\Math_BigInteger $n, \Math_BigInteger $d){ |
|
77 | + public function buildMinimalPrivateKey(\Math_BigInteger $n, \Math_BigInteger $d) { |
|
78 | 78 | $this->rsa_imp->modulus = $n; |
79 | 79 | $this->rsa_imp->exponent = $d; |
80 | 80 | $private_key_pem = $this->rsa_imp->_getPrivatePublicKey(); |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | BigInteger $q, |
100 | 100 | BigInteger $dp, |
101 | 101 | BigInteger $dq, |
102 | - BigInteger $qi){ |
|
102 | + BigInteger $qi) { |
|
103 | 103 | |
104 | 104 | $private_key_pem = $this->rsa_imp->_convertPrivateKey( |
105 | 105 | $n, |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | * @return RSAPrivateKey |
119 | 119 | * @throws RSABadPEMFormat |
120 | 120 | */ |
121 | - public function buildPrivateKeyFromPEM($private_key_pem, $password = null){ |
|
121 | + public function buildPrivateKeyFromPEM($private_key_pem, $password = null) { |
|
122 | 122 | return new _RSAPrivateKeyPEMFornat($private_key_pem, $password); |
123 | 123 | } |
124 | 124 | |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | * @return RSAPublicKey |
128 | 128 | * @throws RSABadPEMFormat |
129 | 129 | */ |
130 | - public function buildPublicKeyFromPEM($public_key_pem){ |
|
130 | + public function buildPublicKeyFromPEM($public_key_pem) { |
|
131 | 131 | return new _RSAPublicKeyPEMFornat($public_key_pem); |
132 | 132 | } |
133 | 133 |