PluginProbe
ManageWP Worker / 4.9.35
ManageWP Worker v4.9.35
4.9.38 4.9.37 4.9.36 4.9.35 4.9.34 3.8.7 3.8.8 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.18 3.9.19 3.9.2 3.9.20 3.9.21 3.9.22 3.9.23 3.9.24 All 73 releases
worker / src / MWP / Crypter / OpenSslCrypter.php

OpenSslCrypter.php in ManageWP Worker 4.9.35, at src/MWP/Crypter/OpenSslCrypter.php

63 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * This file is part of the ManageWP Worker plugin.
4 *
5 * (c) ManageWP LLC <[email protected]>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10
11 class MWP_Crypter_OpenSslCrypter implements MWP_Crypter_Interface
12 {
13 public function publicEncrypt($data, $publicKey)
14 {
15 $errorCatcher = new MWP_Debug_ErrorCatcher();
16 $errorCatcher->register('openssl_public_encrypt');
17 /** @handled function */
18 $success = @openssl_public_encrypt($data, $crypted, $publicKey);
19 $lastError = $errorCatcher->yieldErrorMessage(true);
20
21 if ($success === false) {
22 $error = $errorRow = '';
23
24 /** @handled function */
25 while (($errorRow = openssl_error_string()) !== false) {
26 $error = $errorRow."\n".$error;
27 }
28
29 throw new MWP_Worker_Exception(MWP_Worker_Exception::OPENSSL_ENCRYPT_ERROR, "There was an error while trying to use OpenSSL to encrypt a message.", array(
30 'openSslError' => $error,
31 'error' => isset($lastError['message']) ? $lastError['message'] : null,
32 ));
33 }
34
35 return $crypted;
36 }
37
38 public function publicDecrypt($data, $publicKey)
39 {
40 $errorCatcher = new MWP_Debug_ErrorCatcher();
41 $errorCatcher->register('openssl_public_decrypt');
42 /** @handled function */
43 $success = @openssl_public_decrypt($data, $decrypted, $publicKey);
44 $lastError = $errorCatcher->yieldErrorMessage(true);
45
46 if ($success === false && $lastError !== null) {
47 $error = $errorRow = '';
48
49 /** @handled function */
50 while (($errorRow = openssl_error_string()) !== false) {
51 $error = $errorRow."\n".$error;
52 }
53
54 throw new MWP_Worker_Exception(MWP_Worker_Exception::OPENSSL_DECRYPT_ERROR, "There was an error while trying to use OpenSSL to decrypt a message.", array(
55 'openSslError' => $error,
56 'error' => $lastError,
57 ));
58 }
59
60 return $decrypted === false ? null : $decrypted;
61 }
62 }
63