Skip to content

Commit 14adcce

Browse files
authored
Fix the presence of padding (#497)
Fix the presence of padding
1 parent 45abec7 commit 14adcce

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

KeyEncryption/AESCTR.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function decryptKey(JWK $key, string $encrypted_cek, array $header): stri
4747
$k = $this->getKey($key);
4848
isset($header['iv']) || throw new InvalidArgumentException('The header parameter "iv" is missing.');
4949
is_string($header['iv']) || throw new InvalidArgumentException('The header parameter "iv" is not valid.');
50-
$iv = Base64UrlSafe::decode($header['iv']);
50+
$iv = Base64UrlSafe::decodeNoPadding($header['iv']);
5151

5252
$result = openssl_decrypt($encrypted_cek, $this->getMode(), $k, OPENSSL_RAW_DATA, $iv);
5353
if ($result === false) {
@@ -77,6 +77,6 @@ private function getKey(JWK $key): string
7777
throw new InvalidArgumentException('The key parameter "k" is invalid.');
7878
}
7979

80-
return Base64UrlSafe::decode($k);
80+
return Base64UrlSafe::decodeNoPadding($k);
8181
}
8282
}

KeyEncryption/Chacha20Poly1305.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function decryptKey(JWK $key, string $encrypted_cek, array $header): stri
6161
$k = $this->getKey($key);
6262
isset($header['nonce']) || throw new InvalidArgumentException('The header parameter "nonce" is missing.');
6363
is_string($header['nonce']) || throw new InvalidArgumentException('The header parameter "nonce" is not valid.');
64-
$nonce = Base64UrlSafe::decode($header['nonce']);
64+
$nonce = Base64UrlSafe::decodeNoPadding($header['nonce']);
6565
if (mb_strlen($nonce, '8bit') !== 12) {
6666
throw new InvalidArgumentException('The header parameter "nonce" is not valid.');
6767
}
@@ -92,6 +92,6 @@ private function getKey(JWK $key): string
9292
throw new InvalidArgumentException('The key parameter "k" is invalid.');
9393
}
9494

95-
return Base64UrlSafe::decode($k);
95+
return Base64UrlSafe::decodeNoPadding($k);
9696
}
9797
}

0 commit comments

Comments
 (0)