Skip to content

Commit 93f1109

Browse files
committed
feat(alg): Add ES512 support
1 parent 500501c commit 93f1109

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/JWT.php

+11-8
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@ class JWT
5353
* @var array<string, string[]>
5454
*/
5555
public static $supported_algs = [
56-
'ES384' => ['openssl', 'SHA384'],
5756
'ES256' => ['openssl', 'SHA256'],
5857
'ES256K' => ['openssl', 'SHA256'],
58+
'ES384' => ['openssl', 'SHA384'],
59+
'ES512' => ['openssl', 'SHA512'],
5960
'HS256' => ['hash_hmac', 'SHA256'],
6061
'HS384' => ['hash_hmac', 'SHA384'],
6162
'HS512' => ['hash_hmac', 'SHA512'],
@@ -75,7 +76,7 @@ class JWT
7576
* the public key.
7677
* Each Key object contains an algorithm and
7778
* matching key.
78-
* Supported algorithms are 'ES384','ES256',
79+
* Supported algorithms are 'ES256', 'ES256K', 'ES384', 'ES512',
7980
* 'HS256', 'HS384', 'HS512', 'RS256', 'RS384'
8081
* and 'RS512'.
8182
* @param stdClass $headers Optional. Populates stdClass with headers.
@@ -142,8 +143,8 @@ public static function decode(
142143
// See issue #351
143144
throw new UnexpectedValueException('Incorrect key for this algorithm');
144145
}
145-
if (\in_array($header->alg, ['ES256', 'ES256K', 'ES384'], true)) {
146-
// OpenSSL expects an ASN.1 DER sequence for ES256/ES256K/ES384 signatures
146+
if (\in_array($header->alg, ['ES256', 'ES256K', 'ES384', 'ES512'], true)) {
147+
// OpenSSL expects an ASN.1 DER sequence for ES256/ES256K/ES384/ES512 signatures
147148
$sig = self::signatureToDER($sig);
148149
}
149150
if (!self::verify("{$headb64}.{$bodyb64}", $sig, $key->getKeyMaterial(), $header->alg)) {
@@ -186,8 +187,8 @@ public static function decode(
186187
*
187188
* @param array<mixed> $payload PHP array
188189
* @param string|resource|OpenSSLAsymmetricKey|OpenSSLCertificate $key The secret key.
189-
* @param string $alg Supported algorithms are 'ES384','ES256', 'ES256K', 'HS256',
190-
* 'HS384', 'HS512', 'RS256', 'RS384', and 'RS512'
190+
* @param string $alg Supported algorithms are 'ES256', 'ES256K', 'ES384', 'ES512',
191+
* 'HS256', 'HS384', 'HS512', 'RS256', 'RS384', and 'RS512'
191192
* @param string $keyId
192193
* @param array<string, string> $head An array with header elements to attach
193194
*
@@ -227,8 +228,8 @@ public static function encode(
227228
*
228229
* @param string $msg The message to sign
229230
* @param string|resource|OpenSSLAsymmetricKey|OpenSSLCertificate $key The secret key.
230-
* @param string $alg Supported algorithms are 'EdDSA', 'ES384', 'ES256', 'ES256K', 'HS256',
231-
* 'HS384', 'HS512', 'RS256', 'RS384', and 'RS512'
231+
* @param string $alg Supported algorithms are 'EdDSA', 'ES256', 'ES256K', 'ES384', 'ES512',
232+
* 'HS256', 'HS384', 'HS512', 'RS256', 'RS384', and 'RS512'
232233
*
233234
* @return string An encrypted message
234235
*
@@ -262,6 +263,8 @@ public static function sign(
262263
$signature = self::signatureFromDER($signature, 256);
263264
} elseif ($alg === 'ES384') {
264265
$signature = self::signatureFromDER($signature, 384);
266+
} elseif ($alg === 'ES512') {
267+
$signature = self::signatureFromDER($signature, 512);
265268
}
266269
return $signature;
267270
case 'sodium_crypto':

0 commit comments

Comments
 (0)