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

Commit 9caa1d3

Browse files
committed
Fixed an issue with primitive type encryption
1 parent 3b2fa76 commit 9caa1d3

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/Developer/Encryption/FieldLevelEncryption.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ private static function encryptPayloadPath($payloadJsonObject, $jsonPathIn, $jso
9393
}
9494

9595
// Encrypt data at the given JSON path
96-
$inJsonString = self::sanitizeJson(json_encode($inJsonObject));
96+
$inJsonString = self::sanitizeJson(self::toJsonString($inJsonObject));
9797
$encryptedValueBytes = self::encryptBytes($params->getSecretKeyBytes(), $params->getIvBytes(), $inJsonString);
9898
$encryptedValue = EncodingUtils::encodeBytes($encryptedValueBytes, $config->getFieldValueEncoding());
9999

@@ -261,6 +261,16 @@ private static function decryptBytes($key, $iv, $encryptedBytes) {
261261
return $bytes;
262262
}
263263

264+
private static function toJsonString($object) {
265+
if (is_null($object)) {
266+
throw new \InvalidArgumentException('Can\'t get a JSON string from a null object!');
267+
}
268+
if (!is_object($object) && !is_array($object)) {
269+
return $object;
270+
}
271+
return json_encode($object);
272+
}
273+
264274
private static function sanitizeJson($json) {
265275
$json = str_replace("\n", '', $json);
266276
$json = str_replace("\r", '', $json);

0 commit comments

Comments
 (0)