Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 11 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| Encryption | |
0.00% |
0 / 11 |
|
0.00% |
0 / 3 |
20 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| encrypt | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| decrypt | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | namespace BuyerKiosk\Security; |
| 3 | |
| 4 | class Encryption { |
| 5 | private $key; |
| 6 | private $cipher = "aes-256-cbc"; |
| 7 | |
| 8 | public function __construct($key) { |
| 9 | $this->key = $key; |
| 10 | } |
| 11 | |
| 12 | public function encrypt($plaintext) { |
| 13 | $iv = str_repeat("\0", 16); // Create 16-byte IV |
| 14 | $ciphertext = openssl_encrypt($plaintext, $this->cipher, $this->key, OPENSSL_RAW_DATA, $iv); |
| 15 | return base64_encode($ciphertext); |
| 16 | } |
| 17 | |
| 18 | public function decrypt($encrypted) { |
| 19 | $iv = str_repeat("\0", 16); // Use same 16-byte IV |
| 20 | $ciphertext = base64_decode($encrypted); // Ensure base64 decoding |
| 21 | error_log("Ciphertext: " . print_r($ciphertext, true)); |
| 22 | $decrypted = openssl_decrypt($ciphertext, $this->cipher, $this->key, OPENSSL_RAW_DATA, $iv); |
| 23 | |
| 24 | if ($decrypted === false) { |
| 25 | error_log("Decryption failed: " . openssl_error_string()); |
| 26 | } |
| 27 | |
| 28 | return $decrypted; |
| 29 | } |
| 30 | } |