|
4 | 4 |
|
5 | 5 | use const OPENSSL_ALGO_SHA256;
|
6 | 6 | use const OPENSSL_PKCS1_OAEP_PADDING;
|
7 |
| -use const OPENSSL_PKCS1_PADDING; |
8 | 7 | use const PHP_URL_SCHEME;
|
9 | 8 |
|
10 | 9 | use function array_column;
|
@@ -237,34 +236,25 @@ private static function parse($thing, string $type = self::KEY_TYPE_PRIVATE)
|
237 | 236 | }
|
238 | 237 |
|
239 | 238 | /**
|
240 |
| - * Check the RSA padding mode either `OPENSSL_PKCS1_PADDING` or `OPENSSL_PKCS1_OAEP_PADDING`. |
| 239 | + * Check the padding mode whether or nor supported. |
241 | 240 | *
|
242 |
| - * **Warning:** |
243 |
| - * |
244 |
| - * Decryption failures in the `RSA_PKCS1_PADDING` mode leak information which can potentially be used to mount a Bleichenbacher padding oracle attack. |
245 |
| - * This is an inherent weakness in the PKCS #1 v1.5 padding design. Prefer `RSA_PKCS1_OAEP_PADDING`. |
246 |
| - * |
247 |
| - * @link https://www.openssl.org/docs/man1.1.1/man3/RSA_public_encrypt.html |
248 |
| - * |
249 |
| - * @param int $padding - The padding mode, only support `OPENSSL_PKCS1_PADDING` or `OPENSSL_PKCS1_OAEP_PADDING`, otherwise thrown `\UnexpectedValueException`. |
| 241 | + * @param int $padding - The padding mode, only support `OPENSSL_PKCS1_PADDING`, otherwise thrown `\UnexpectedValueException`. |
250 | 242 | *
|
251 | 243 | * @throws UnexpectedValueException
|
252 | 244 | */
|
253 | 245 | private static function paddingModeLimitedCheck(int $padding): void
|
254 | 246 | {
|
255 |
| - if (!($padding === OPENSSL_PKCS1_OAEP_PADDING || $padding === OPENSSL_PKCS1_PADDING)) { |
256 |
| - throw new UnexpectedValueException(sprintf("Doesn't supported padding mode(%d), here only support OPENSSL_PKCS1_OAEP_PADDING or OPENSSL_PKCS1_PADDING.", $padding)); |
| 247 | + if ($padding !== OPENSSL_PKCS1_OAEP_PADDING) { |
| 248 | + throw new UnexpectedValueException(sprintf('Here\'s only support the OPENSSL_PKCS1_OAEP_PADDING(4) mode, yours(%d).', $padding)); |
257 | 249 | }
|
258 | 250 | }
|
259 | 251 |
|
260 | 252 | /**
|
261 | 253 | * Encrypts text by the given `$publicKey` in the `$padding`(default is `OPENSSL_PKCS1_OAEP_PADDING`) mode.
|
262 | 254 | *
|
263 |
| - * Some of APIs were required the `$padding` mode as of `RSAES-PKCS1-v1_5` which is equal to the `OPENSSL_PKCS1_PADDING` constant, exposed it for this case. |
264 |
| - * |
265 | 255 | * @param string $plaintext - Cleartext to encode.
|
266 | 256 | * @param \OpenSSLAsymmetricKey|\OpenSSLCertificate|resource|string|mixed $publicKey - The public key.
|
267 |
| - * @param int $padding - One of OPENSSL_PKCS1_PADDING, OPENSSL_PKCS1_OAEP_PADDING, default is `OPENSSL_PKCS1_OAEP_PADDING`. |
| 257 | + * @param int $padding - default is `OPENSSL_PKCS1_OAEP_PADDING`. |
268 | 258 | *
|
269 | 259 | * @return string - The base64-encoded ciphertext.
|
270 | 260 | * @throws UnexpectedValueException
|
@@ -320,11 +310,9 @@ public static function sign(string $message, $privateKey): string
|
320 | 310 | /**
|
321 | 311 | * Decrypts base64 encoded string with `$privateKey` in the `$padding`(default is `OPENSSL_PKCS1_OAEP_PADDING`) mode.
|
322 | 312 | *
|
323 |
| - * Some of APIs were required the `$padding` mode as of `RSAES-PKCS1-v1_5` which is equal to the `OPENSSL_PKCS1_PADDING` constant, exposed it for this case. |
324 |
| - * |
325 | 313 | * @param string $ciphertext - Was previously encrypted string using the corresponding public key.
|
326 | 314 | * @param \OpenSSLAsymmetricKey|\OpenSSLCertificate|resource|string|array{string,string}|mixed $privateKey - The private key.
|
327 |
| - * @param int $padding - One of OPENSSL_PKCS1_PADDING, OPENSSL_PKCS1_OAEP_PADDING, default is `OPENSSL_PKCS1_OAEP_PADDING`. |
| 315 | + * @param int $padding - default is `OPENSSL_PKCS1_OAEP_PADDING`. |
328 | 316 | *
|
329 | 317 | * @return string - The utf-8 plaintext.
|
330 | 318 | * @throws UnexpectedValueException
|
|
0 commit comments