1 | <?php |
||
22 | abstract class RSAESKeyAlgorithm extends KeyManagementAlgorithm |
||
23 | { |
||
24 | use RandomCEK; |
||
25 | |||
26 | /** |
||
27 | * Public key. |
||
28 | * |
||
29 | * @var RSAPublicKeyJWK $_publicKey |
||
30 | */ |
||
31 | protected $_publicKey; |
||
32 | |||
33 | /** |
||
34 | * Private key. |
||
35 | * |
||
36 | * @var RSAPrivateKeyJWK|null $_privateKey |
||
37 | */ |
||
38 | protected $_privateKey; |
||
39 | |||
40 | /** |
||
41 | * Mapping from algorithm name to class name. |
||
42 | * |
||
43 | * @internal |
||
44 | * |
||
45 | * @var array |
||
46 | */ |
||
47 | const MAP_ALGO_TO_CLASS = array( |
||
48 | /* @formatter:off */ |
||
49 | JWA::ALGO_RSA1_5 => RSAESPKCS1Algorithm::class, |
||
50 | JWA::ALGO_RSA_OAEP => RSAESOAEPAlgorithm::class |
||
51 | /* @formatter:on */ |
||
52 | ); |
||
53 | |||
54 | /** |
||
55 | * Get the padding scheme. |
||
56 | * |
||
57 | * @return int |
||
58 | */ |
||
59 | abstract protected function _paddingScheme(): int; |
||
60 | |||
61 | /** |
||
62 | * Constructor. |
||
63 | * |
||
64 | * Use <code>fromPublicKey</code> or <code>fromPrivateKey</code> instead! |
||
65 | * |
||
66 | * @param RSAPublicKeyJWK $pub_key RSA public key |
||
67 | * @param RSAPrivateKeyJWK $priv_key Optional RSA private key |
||
68 | */ |
||
69 | 18 | protected function __construct(RSAPublicKeyJWK $pub_key, |
|
75 | |||
76 | /** |
||
77 | * |
||
78 | * @param JWK $jwk |
||
79 | * @param Header $header |
||
80 | * @throws \UnexpectedValueException |
||
81 | * @return self |
||
82 | */ |
||
83 | 3 | public static function fromJWK(JWK $jwk, Header $header) |
|
95 | |||
96 | /** |
||
97 | * Initialize from a public key. |
||
98 | * |
||
99 | * @param RSAPublicKeyJWK $jwk |
||
100 | * @return self |
||
101 | */ |
||
102 | 3 | public static function fromPublicKey(RSAPublicKeyJWK $jwk): self |
|
106 | |||
107 | /** |
||
108 | * Initialize from a private key. |
||
109 | * |
||
110 | * @param RSAPrivateKeyJWK $jwk |
||
111 | * @return self |
||
112 | */ |
||
113 | 15 | public static function fromPrivateKey(RSAPrivateKeyJWK $jwk): self |
|
117 | |||
118 | /** |
||
119 | * Get the public key. |
||
120 | * |
||
121 | * @return RSAPublicKeyJWK |
||
122 | */ |
||
123 | 10 | public function publicKey(): RSAPublicKeyJWK |
|
127 | |||
128 | /** |
||
129 | * Check whether the private key is present. |
||
130 | * |
||
131 | * @return bool |
||
132 | */ |
||
133 | 12 | public function hasPrivateKey(): bool |
|
137 | |||
138 | /** |
||
139 | * Get the private key. |
||
140 | * |
||
141 | * @throws \LogicException |
||
142 | * @return RSAPrivateKeyJWK |
||
143 | */ |
||
144 | 11 | public function privateKey(): RSAPrivateKeyJWK |
|
151 | |||
152 | /** |
||
153 | * |
||
154 | * {@inheritdoc} |
||
155 | */ |
||
156 | 9 | protected function _encryptKey(string $key, Header &$header): string |
|
176 | |||
177 | /** |
||
178 | * |
||
179 | * {@inheritdoc} |
||
180 | */ |
||
181 | 9 | protected function _decryptKey(string $ciphertext, Header $header): string |
|
201 | |||
202 | /** |
||
203 | * Get last OpenSSL error message. |
||
204 | * |
||
205 | * @return string|null |
||
206 | */ |
||
207 | 2 | protected function _getLastOpenSSLError() |
|
215 | |||
216 | /** |
||
217 | * |
||
218 | * @see \JWX\JWE\KeyManagementAlgorithm::headerParameters() |
||
219 | * @return \JWX\JWT\Parameter\JWTParameter[] |
||
220 | */ |
||
221 | 3 | public function headerParameters(): array |
|
226 | } |
||
227 |