Skip to content

Commit 25728d4

Browse files
committed
base64 iv in payload
1 parent 2e6edbf commit 25728d4

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

src/Extension/Cryptography/BaseCryptographer.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
use Patchlevel\Hydrator\Extension\Cryptography\Store\CipherKeyStore;
1616

1717
use function array_key_exists;
18+
use function base64_decode;
19+
use function base64_encode;
1820
use function is_array;
1921

2022
/**
@@ -52,7 +54,7 @@ public function encrypt(string $subjectId, mixed $value): array
5254
'__enc' => 'v1',
5355
'data' => $this->cipher->encrypt($cipherKey, $value),
5456
'method' => $cipherKey->method,
55-
'iv' => $cipherKey->iv,
57+
'iv' => base64_encode($cipherKey->iv),
5658
];
5759
}
5860

@@ -70,7 +72,7 @@ public function decrypt(string $subjectId, mixed $encryptedData): mixed
7072
new CipherKey(
7173
$cipherKey->key,
7274
$encryptedData['method'] ?? $cipherKey->method,
73-
$encryptedData['iv'] ?? $cipherKey->iv,
75+
isset($encryptedData['iv']) ? base64_decode($encryptedData['iv']) : $cipherKey->iv,
7476
),
7577
$encryptedData['data'],
7678
);

tests/Unit/Extension/Cryptography/BaseCryptographerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function testEncrypt(): void
4646
'__enc' => 'v1',
4747
'data' => 'encrypted',
4848
'method' => 'methodA',
49-
'iv' => 'random',
49+
'iv' => 'cmFuZG9t',
5050
];
5151

5252
self::assertEquals($expected, $cryptographer->encrypt('foo', 'info@patchlevel.de'));
@@ -81,7 +81,7 @@ public function testEncryptWithoutKey(): void
8181
'__enc' => 'v1',
8282
'data' => 'encrypted',
8383
'method' => 'methodA',
84-
'iv' => 'random',
84+
'iv' => 'cmFuZG9t',
8585
];
8686

8787
self::assertEquals($expected, $cryptographer->encrypt('foo', 'info@patchlevel.de'));
@@ -115,7 +115,7 @@ public function testDecrypt(): void
115115
'__enc' => 'v1',
116116
'data' => 'encrypted',
117117
'method' => 'methodA',
118-
'iv' => 'random',
118+
'iv' => 'cmFuZG9t',
119119
],
120120
),
121121
);

0 commit comments

Comments
 (0)