@@ -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()); |
@@ -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 |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | /** |
51 | 51 | * @return null|string |
52 | 52 | */ |
53 | - public function getPassword():?string{ |
|
53 | + public function getPassword(): ?string{ |
|
54 | 54 | return $this->password; |
55 | 55 | } |
56 | 56 | |
@@ -66,18 +66,18 @@ discard block |
||
66 | 66 | * @param string $password |
67 | 67 | * @throws RSABadPEMFormat |
68 | 68 | */ |
69 | - public function __construct($pem_format, $password = null){ |
|
69 | + public function __construct($pem_format, $password = null) { |
|
70 | 70 | |
71 | 71 | $this->pem_format = $pem_format; |
72 | 72 | $this->rsa_imp = new RSA(); |
73 | 73 | |
74 | - if(!empty($password)) { |
|
74 | + if (!empty($password)) { |
|
75 | 75 | $this->password = trim($password); |
76 | 76 | $this->rsa_imp->setPassword($this->password); |
77 | 77 | } |
78 | 78 | |
79 | 79 | $res = $this->rsa_imp->loadKey($this->pem_format, RSA::PRIVATE_FORMAT_PKCS1); |
80 | - if(!$res) throw new RSABadPEMFormat(sprintf('pem %s',$pem_format )); |
|
80 | + if (!$res) throw new RSABadPEMFormat(sprintf('pem %s', $pem_format)); |
|
81 | 81 | |
82 | 82 | $this->key = PublicKeyLoader::load($this->pem_format, $this->password)->toString('raw'); |
83 | 83 |
@@ -77,7 +77,9 @@ |
||
77 | 77 | } |
78 | 78 | |
79 | 79 | $res = $this->rsa_imp->loadKey($this->pem_format, RSA::PRIVATE_FORMAT_PKCS1); |
80 | - if(!$res) throw new RSABadPEMFormat(sprintf('pem %s',$pem_format )); |
|
80 | + if(!$res) { |
|
81 | + throw new RSABadPEMFormat(sprintf('pem %s',$pem_format )); |
|
82 | + } |
|
81 | 83 | |
82 | 84 | $this->key = PublicKeyLoader::load($this->pem_format, $this->password)->toString('raw'); |
83 | 85 |
@@ -34,17 +34,17 @@ discard block |
||
34 | 34 | */ |
35 | 35 | private $rsa_imp; |
36 | 36 | |
37 | - private function __construct(){ |
|
37 | + private function __construct() { |
|
38 | 38 | $this->rsa_imp = new RSA(); |
39 | 39 | } |
40 | 40 | |
41 | - private function __clone(){} |
|
41 | + private function __clone() {} |
|
42 | 42 | |
43 | 43 | /** |
44 | 44 | * @return RSAFacade |
45 | 45 | */ |
46 | - public static function getInstance(){ |
|
47 | - if(!is_object(self::$instance)){ |
|
46 | + public static function getInstance() { |
|
47 | + if (!is_object(self::$instance)) { |
|
48 | 48 | self::$instance = new RSAFacade(); |
49 | 49 | } |
50 | 50 | return self::$instance; |
@@ -54,12 +54,12 @@ discard block |
||
54 | 54 | * @param $bits |
55 | 55 | * @return KeyPair |
56 | 56 | */ |
57 | - public function buildKeyPair($bits){ |
|
57 | + public function buildKeyPair($bits) { |
|
58 | 58 | $this->rsa_imp->setPrivateKeyFormat(RSA::PRIVATE_FORMAT_PKCS1); |
59 | 59 | $this->rsa_imp->setPublicKeyFormat(RSA::PUBLIC_FORMAT_PKCS1); |
60 | 60 | |
61 | 61 | $list = $this->rsa_imp->createKey($bits); |
62 | - return new KeyPair( new _RSAPublicKeyPEMFormat($list['publickey']), new _RSAPrivateKeyPEMFormat($list['privatekey'])); |
|
62 | + return new KeyPair(new _RSAPublicKeyPEMFormat($list['publickey']), new _RSAPrivateKeyPEMFormat($list['privatekey'])); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | * @param BigInteger $e |
68 | 68 | * @return RSAPublicKey |
69 | 69 | */ |
70 | - public function buildPublicKey(BigInteger $n, BigInteger $e){ |
|
70 | + public function buildPublicKey(BigInteger $n, BigInteger $e) { |
|
71 | 71 | |
72 | 72 | |
73 | 73 | $key = PublicKeyLoader::load([ |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | * @param \Math_BigInteger $d |
85 | 85 | * @return RSAPrivateKey |
86 | 86 | */ |
87 | - public function buildMinimalPrivateKey(\Math_BigInteger $n, \Math_BigInteger $d){ |
|
87 | + public function buildMinimalPrivateKey(\Math_BigInteger $n, \Math_BigInteger $d) { |
|
88 | 88 | $this->rsa_imp->modulus = $n; |
89 | 89 | $this->rsa_imp->exponent = $d; |
90 | 90 | $private_key_pem = $this->rsa_imp->_getPrivatePublicKey(); |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | BigInteger $q, |
110 | 110 | BigInteger $dp, |
111 | 111 | BigInteger $dq, |
112 | - BigInteger $qi){ |
|
112 | + BigInteger $qi) { |
|
113 | 113 | |
114 | 114 | $private_key_pem = $this->rsa_imp->_convertPrivateKey( |
115 | 115 | $n, |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | * @return RSAPrivateKey |
129 | 129 | * @throws RSABadPEMFormat |
130 | 130 | */ |
131 | - public function buildPrivateKeyFromPEM($private_key_pem, $password = null){ |
|
131 | + public function buildPrivateKeyFromPEM($private_key_pem, $password = null) { |
|
132 | 132 | return new _RSAPrivateKeyPEMFormat($private_key_pem, $password); |
133 | 133 | } |
134 | 134 | |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | * @return RSAPublicKey |
138 | 138 | * @throws RSABadPEMFormat |
139 | 139 | */ |
140 | - public function buildPublicKeyFromPEM($public_key_pem){ |
|
140 | + public function buildPublicKeyFromPEM($public_key_pem) { |
|
141 | 141 | return new _RSAPublicKeyPEMFormat($public_key_pem); |
142 | 142 | } |
143 | 143 |
@@ -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->key['e']; |
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 |
@@ -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->key['d']; |
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 |
@@ -36,8 +36,9 @@ |
||
36 | 36 | |
37 | 37 | parent::__construct($pem_format, $password); |
38 | 38 | $this->d = $this->key['d']; |
39 | - if($this->d->toString() === $this->e->toString()) |
|
40 | - throw new RSABadPEMFormat(sprintf('pem %s is a public key!', $pem_format)); |
|
39 | + if($this->d->toString() === $this->e->toString()) { |
|
40 | + throw new RSABadPEMFormat(sprintf('pem %s is a public key!', $pem_format)); |
|
41 | + } |
|
41 | 42 | } |
42 | 43 | |
43 | 44 | /** |