1 | <?php |
||
25 | final class RSAKey |
||
26 | { |
||
27 | /** |
||
28 | * @var Sequence |
||
29 | */ |
||
30 | private $sequence; |
||
31 | |||
32 | /** |
||
33 | * @var bool |
||
34 | */ |
||
35 | private $private = false; |
||
36 | |||
37 | /** |
||
38 | * @var array |
||
39 | */ |
||
40 | private $values = []; |
||
41 | |||
42 | /** |
||
43 | * @var BigInteger |
||
44 | */ |
||
45 | private $modulus; |
||
46 | |||
47 | /** |
||
48 | * @var int |
||
49 | */ |
||
50 | private $modulus_length; |
||
51 | |||
52 | /** |
||
53 | * @var BigInteger |
||
54 | */ |
||
55 | private $public_exponent; |
||
56 | |||
57 | /** |
||
58 | * @var BigInteger|null |
||
59 | */ |
||
60 | private $private_exponent = null; |
||
61 | |||
62 | /** |
||
63 | * @var BigInteger[] |
||
64 | */ |
||
65 | private $primes = []; |
||
66 | |||
67 | /** |
||
68 | * @var BigInteger[] |
||
69 | */ |
||
70 | private $exponents = []; |
||
71 | |||
72 | /** |
||
73 | * @var BigInteger|null |
||
74 | */ |
||
75 | private $coefficient = null; |
||
76 | |||
77 | /** |
||
78 | * @param JWK $data |
||
79 | */ |
||
80 | private function __construct(JWK $data) |
||
86 | |||
87 | /** |
||
88 | * @param JWK $jwk |
||
89 | * |
||
90 | * @return RSAKey |
||
91 | */ |
||
92 | public static function createFromJWK(JWK $jwk): RSAKey |
||
96 | |||
97 | /** |
||
98 | * @return BigInteger |
||
99 | */ |
||
100 | public function getModulus(): BigInteger |
||
104 | |||
105 | /** |
||
106 | * @return int |
||
107 | */ |
||
108 | public function getModulusLength(): int |
||
112 | |||
113 | /** |
||
114 | * @return BigInteger |
||
115 | */ |
||
116 | public function getExponent(): BigInteger |
||
125 | |||
126 | /** |
||
127 | * @return BigInteger |
||
128 | */ |
||
129 | public function getPublicExponent(): BigInteger |
||
133 | |||
134 | /** |
||
135 | * @return BigInteger|null |
||
136 | */ |
||
137 | public function getPrivateExponent(): ?BigInteger |
||
141 | |||
142 | /** |
||
143 | * @return BigInteger[] |
||
144 | */ |
||
145 | public function getPrimes(): array |
||
149 | |||
150 | /** |
||
151 | * @return BigInteger[] |
||
152 | */ |
||
153 | public function getExponents(): array |
||
157 | |||
158 | /** |
||
159 | * @return BigInteger|null |
||
160 | */ |
||
161 | public function getCoefficient(): ?BigInteger |
||
165 | |||
166 | /** |
||
167 | * @return bool |
||
168 | */ |
||
169 | public function isPublic(): bool |
||
173 | |||
174 | /** |
||
175 | * @param RSAKey $private |
||
176 | * |
||
177 | * @return RSAKey |
||
178 | */ |
||
179 | public static function toPublic(RSAKey $private): RSAKey |
||
191 | |||
192 | /** |
||
193 | * @return array |
||
194 | */ |
||
195 | public function toArray(): array |
||
199 | |||
200 | /** |
||
201 | * @param array $jwk |
||
202 | */ |
||
203 | private function loadJWK(array $jwk) |
||
214 | |||
215 | private function populateBigIntegers() |
||
239 | |||
240 | /** |
||
241 | * @param string $value |
||
242 | * |
||
243 | * @return BigInteger |
||
244 | */ |
||
245 | private function convertBase64StringToBigInteger(string $value): BigInteger |
||
249 | |||
250 | /** |
||
251 | * @return string |
||
252 | */ |
||
253 | public function toPEM(): string |
||
269 | |||
270 | /** |
||
271 | * @throws \Exception |
||
272 | */ |
||
273 | private function initPublicKey() |
||
316 | |||
317 | /** |
||
318 | * @param string $value |
||
319 | * |
||
320 | * @return string |
||
321 | */ |
||
322 | private function fromBase64ToInteger($value) |
||
326 | } |
||
327 |