Skip to content
This repository was archived by the owner on Feb 28, 2024. It is now read-only.

Commit 7f7ac4c

Browse files
committed
Switched to phpseclib for AES
1 parent 56e9846 commit 7f7ac4c

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/Developer/Encryption/FieldLevelEncryption.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
44

55
use Mastercard\Developer\Json\JsonPath;
66
use Mastercard\Developer\Utils\EncodingUtils;
7+
use phpseclib\Crypt\AES;
78

89
/**
910
* Performs field level encryption on HTTP payloads.
1011
* @package Mastercard\Developer\Encryption
1112
*/
1213
class FieldLevelEncryption {
1314

14-
const SYMMETRIC_CYPHER = 'AES-128-CBC';
15-
1615
private function __construct() {}
1716

1817
/**
@@ -241,15 +240,21 @@ private static function readAndDeleteJsonKey($object, $key) {
241240
}
242241

243242
private static function encryptBytes($key, $iv, $bytes) {
244-
$encryptedBytes = openssl_encrypt($bytes, self::SYMMETRIC_CYPHER, $key, OPENSSL_RAW_DATA, $iv);
243+
$aes = new AES();
244+
$aes->setKey($key);
245+
$aes->setIV($iv);
246+
$encryptedBytes = $aes->encrypt($bytes);
245247
if (false === $encryptedBytes) {
246248
throw new EncryptionException('Failed to encrypt bytes!');
247249
}
248250
return $encryptedBytes;
249251
}
250252

251253
private static function decryptBytes($key, $iv, $encryptedBytes) {
252-
$bytes = openssl_decrypt($encryptedBytes, self::SYMMETRIC_CYPHER, $key, OPENSSL_RAW_DATA, $iv);
254+
$aes = new AES();
255+
$aes->setKey($key);
256+
$aes->setIV($iv);
257+
$bytes = $aes->decrypt($encryptedBytes);
253258
if (false === $bytes) {
254259
throw new EncryptionException('Failed to decrypt bytes with the provided key and IV!');
255260
}

0 commit comments

Comments
 (0)