@@ -39,18 +39,18 @@ discard block |
||
39 | 39 | */ |
40 | 40 | public function sign(PrivateKey $private_key, $message) |
41 | 41 | { |
42 | - if(!($private_key instanceof RSAPrivateKey)) throw new InvalidKeyTypeAlgorithmException; |
|
42 | + if (!($private_key instanceof RSAPrivateKey)) throw new InvalidKeyTypeAlgorithmException; |
|
43 | 43 | |
44 | - if($this->getMinKeyLen() > $private_key->getBitLength()) |
|
45 | - throw new InvalidKeyLengthAlgorithmException(sprintf('min len %s - cur len %s.',$this->getMinKeyLen(), $private_key->getBitLength())); |
|
44 | + if ($this->getMinKeyLen() > $private_key->getBitLength()) |
|
45 | + throw new InvalidKeyLengthAlgorithmException(sprintf('min len %s - cur len %s.', $this->getMinKeyLen(), $private_key->getBitLength())); |
|
46 | 46 | |
47 | - if($private_key->hasPassword()){ |
|
47 | + if ($private_key->hasPassword()) { |
|
48 | 48 | $this->rsa_impl->setPassword($private_key->getPassword()); |
49 | 49 | } |
50 | 50 | |
51 | 51 | $res = $this->rsa_impl->loadKey($private_key->getEncoded()); |
52 | 52 | |
53 | - if(!$res) |
|
53 | + if (!$res) |
|
54 | 54 | throw new InvalidKeyTypeAlgorithmException; |
55 | 55 | |
56 | 56 | $this->rsa_impl->setHash($this->getHashingAlgorithm()); |
@@ -69,14 +69,14 @@ discard block |
||
69 | 69 | */ |
70 | 70 | public function verify(Key $key, $message, $signature) |
71 | 71 | { |
72 | - if(!($key instanceof RSAPublicKey)) throw new InvalidKeyTypeAlgorithmException; |
|
72 | + if (!($key instanceof RSAPublicKey)) throw new InvalidKeyTypeAlgorithmException; |
|
73 | 73 | |
74 | - if($this->getMinKeyLen() > $key->getBitLength()) |
|
75 | - throw new InvalidKeyLengthAlgorithmException(sprintf('min len %s - cur len %s.',$this->getMinKeyLen(), $key->getBitLength())); |
|
74 | + if ($this->getMinKeyLen() > $key->getBitLength()) |
|
75 | + throw new InvalidKeyLengthAlgorithmException(sprintf('min len %s - cur len %s.', $this->getMinKeyLen(), $key->getBitLength())); |
|
76 | 76 | |
77 | 77 | $res = $this->rsa_impl->loadKey($key->getEncoded()); |
78 | 78 | |
79 | - if(!$res) throw new InvalidKeyTypeAlgorithmException; |
|
79 | + if (!$res) throw new InvalidKeyTypeAlgorithmException; |
|
80 | 80 | |
81 | 81 | $this->rsa_impl->setHash($this->getHashingAlgorithm()); |
82 | 82 | $this->rsa_impl->setMGFHash($this->getHashingAlgorithm()); |
@@ -39,10 +39,13 @@ discard block |
||
39 | 39 | */ |
40 | 40 | public function sign(PrivateKey $private_key, $message) |
41 | 41 | { |
42 | - if(!($private_key instanceof RSAPrivateKey)) throw new InvalidKeyTypeAlgorithmException; |
|
42 | + if(!($private_key instanceof RSAPrivateKey)) { |
|
43 | + throw new InvalidKeyTypeAlgorithmException; |
|
44 | + } |
|
43 | 45 | |
44 | - if($this->getMinKeyLen() > $private_key->getBitLength()) |
|
45 | - throw new InvalidKeyLengthAlgorithmException(sprintf('min len %s - cur len %s.',$this->getMinKeyLen(), $private_key->getBitLength())); |
|
46 | + if($this->getMinKeyLen() > $private_key->getBitLength()) { |
|
47 | + throw new InvalidKeyLengthAlgorithmException(sprintf('min len %s - cur len %s.',$this->getMinKeyLen(), $private_key->getBitLength())); |
|
48 | + } |
|
46 | 49 | |
47 | 50 | if($private_key->hasPassword()){ |
48 | 51 | $this->rsa_impl->setPassword($private_key->getPassword()); |
@@ -50,8 +53,9 @@ discard block |
||
50 | 53 | |
51 | 54 | $res = $this->rsa_impl->loadKey($private_key->getEncoded()); |
52 | 55 | |
53 | - if(!$res) |
|
54 | - throw new InvalidKeyTypeAlgorithmException; |
|
56 | + if(!$res) { |
|
57 | + throw new InvalidKeyTypeAlgorithmException; |
|
58 | + } |
|
55 | 59 | |
56 | 60 | $this->rsa_impl->setHash($this->getHashingAlgorithm()); |
57 | 61 | $this->rsa_impl->setMGFHash($this->getHashingAlgorithm()); |
@@ -69,14 +73,19 @@ discard block |
||
69 | 73 | */ |
70 | 74 | public function verify(Key $key, $message, $signature) |
71 | 75 | { |
72 | - if(!($key instanceof RSAPublicKey)) throw new InvalidKeyTypeAlgorithmException; |
|
76 | + if(!($key instanceof RSAPublicKey)) { |
|
77 | + throw new InvalidKeyTypeAlgorithmException; |
|
78 | + } |
|
73 | 79 | |
74 | - if($this->getMinKeyLen() > $key->getBitLength()) |
|
75 | - throw new InvalidKeyLengthAlgorithmException(sprintf('min len %s - cur len %s.',$this->getMinKeyLen(), $key->getBitLength())); |
|
80 | + if($this->getMinKeyLen() > $key->getBitLength()) { |
|
81 | + throw new InvalidKeyLengthAlgorithmException(sprintf('min len %s - cur len %s.',$this->getMinKeyLen(), $key->getBitLength())); |
|
82 | + } |
|
76 | 83 | |
77 | 84 | $res = $this->rsa_impl->loadKey($key->getEncoded()); |
78 | 85 | |
79 | - if(!$res) throw new InvalidKeyTypeAlgorithmException; |
|
86 | + if(!$res) { |
|
87 | + throw new InvalidKeyTypeAlgorithmException; |
|
88 | + } |
|
80 | 89 | |
81 | 90 | $this->rsa_impl->setHash($this->getHashingAlgorithm()); |
82 | 91 | $this->rsa_impl->setMGFHash($this->getHashingAlgorithm()); |
@@ -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 _RSAPublicKeyPEMFormat($list['publickey']), new _RSAPrivateKeyPEMFormat($list['privatekey'])); |
|
59 | + return new KeyPair(new _RSAPublicKeyPEMFormat($list['publickey']), new _RSAPrivateKeyPEMFormat($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 _RSAPublicKeyPEMFormat($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 _RSAPrivateKeyPEMFormat($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 _RSAPublicKeyPEMFormat($public_key_pem); |
132 | 132 | } |
133 | 133 |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | /** |
44 | 44 | * @return null|string |
45 | 45 | */ |
46 | - public function getPassword():?string{ |
|
46 | + public function getPassword(): ?string{ |
|
47 | 47 | return $this->password; |
48 | 48 | } |
49 | 49 | |
@@ -59,19 +59,19 @@ discard block |
||
59 | 59 | * @param string $password |
60 | 60 | * @throws RSABadPEMFormat |
61 | 61 | */ |
62 | - public function __construct($pem_format, $password = null){ |
|
62 | + public function __construct($pem_format, $password = null) { |
|
63 | 63 | |
64 | 64 | $this->pem_format = $pem_format; |
65 | 65 | $this->rsa_imp = new RSA(); |
66 | 66 | |
67 | - if(!empty($password)) { |
|
67 | + if (!empty($password)) { |
|
68 | 68 | $this->password = trim($password); |
69 | 69 | $this->rsa_imp->setPassword($this->password); |
70 | 70 | } |
71 | 71 | |
72 | 72 | $res = $this->rsa_imp->loadKey($this->pem_format, RSA::PRIVATE_FORMAT_PKCS1); |
73 | 73 | |
74 | - if(!$res) throw new RSABadPEMFormat(sprintf('pem %s',$pem_format )); |
|
74 | + if (!$res) throw new RSABadPEMFormat(sprintf('pem %s', $pem_format)); |
|
75 | 75 | |
76 | 76 | $this->n = $this->rsa_imp->modulus; |
77 | 77 | } |
@@ -71,7 +71,9 @@ |
||
71 | 71 | |
72 | 72 | $res = $this->rsa_imp->loadKey($this->pem_format, RSA::PRIVATE_FORMAT_PKCS1); |
73 | 73 | |
74 | - if(!$res) throw new RSABadPEMFormat(sprintf('pem %s',$pem_format )); |
|
74 | + if(!$res) { |
|
75 | + throw new RSABadPEMFormat(sprintf('pem %s',$pem_format )); |
|
76 | + } |
|
75 | 77 | |
76 | 78 | $this->n = $this->rsa_imp->modulus; |
77 | 79 | } |
@@ -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 | |
@@ -71,9 +71,9 @@ discard block |
||
71 | 71 | */ |
72 | 72 | public function getStrippedEncoded(): string |
73 | 73 | { |
74 | - $pem = preg_replace('/\-+BEGIN RSA PRIVATE KEY\-+/','',$this->getEncoded()); |
|
75 | - $pem = preg_replace('/\-+END RSA PRIVATE KEY\-+/','',$pem); |
|
76 | - $pem = str_replace( array("\n","\r","\t"), '', trim($pem)); |
|
74 | + $pem = preg_replace('/\-+BEGIN RSA PRIVATE KEY\-+/', '', $this->getEncoded()); |
|
75 | + $pem = preg_replace('/\-+END RSA PRIVATE KEY\-+/', '', $pem); |
|
76 | + $pem = str_replace(array("\n", "\r", "\t"), '', trim($pem)); |
|
77 | 77 | return $pem; |
78 | 78 | } |
79 | 79 |
@@ -37,8 +37,9 @@ |
||
37 | 37 | |
38 | 38 | parent::__construct($pem_format, $password); |
39 | 39 | $this->d = $this->rsa_imp->exponent; |
40 | - if($this->d->toString() === $this->e->toString()) |
|
41 | - throw new RSABadPEMFormat(sprintf('pem %s is a public key!', $pem_format)); |
|
40 | + if($this->d->toString() === $this->e->toString()) { |
|
41 | + throw new RSABadPEMFormat(sprintf('pem %s is a public key!', $pem_format)); |
|
42 | + } |
|
42 | 43 | } |
43 | 44 | |
44 | 45 | /** |
@@ -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 | } |
@@ -83,9 +83,9 @@ discard block |
||
83 | 83 | */ |
84 | 84 | public function getStrippedEncoded(): string |
85 | 85 | { |
86 | - $pem = preg_replace('/\-+BEGIN PUBLIC KEY\-+/','', $this->getEncoded()); |
|
87 | - $pem = preg_replace('/\-+END PUBLIC KEY\-+/','',$pem); |
|
88 | - $pem = str_replace( array("\n","\r","\t"), '', trim($pem)); |
|
86 | + $pem = preg_replace('/\-+BEGIN PUBLIC KEY\-+/', '', $this->getEncoded()); |
|
87 | + $pem = preg_replace('/\-+END PUBLIC KEY\-+/', '', $pem); |
|
88 | + $pem = str_replace(array("\n", "\r", "\t"), '', trim($pem)); |
|
89 | 89 | return $pem; |
90 | 90 | } |
91 | 91 | } |
92 | 92 | \ No newline at end of file |
@@ -21,7 +21,7 @@ |
||
21 | 21 | /** |
22 | 22 | * @return null|string |
23 | 23 | */ |
24 | - public function getPassword():?string; |
|
24 | + public function getPassword(): ?string; |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * @return bool |