@@ -42,6 +42,7 @@ class JWT
4242 public static $ timestamp = null ;
4343
4444 public static $ supported_algs = array (
45+ 'ES384 ' => array ('openssl ' , 'SHA384 ' ),
4546 'ES256 ' => array ('openssl ' , 'SHA256 ' ),
4647 'HS256 ' => array ('hash_hmac ' , 'SHA256 ' ),
4748 'HS384 ' => array ('hash_hmac ' , 'SHA384 ' ),
@@ -58,7 +59,8 @@ class JWT
5859 * @param string|array|resource $key The key, or map of keys.
5960 * If the algorithm used is asymmetric, this is the public key
6061 * @param array $allowed_algs List of supported verification algorithms
61- * Supported algorithms are 'ES256', 'HS256', 'HS384', 'HS512', 'RS256', 'RS384', and 'RS512'
62+ * Supported algorithms are 'ES384','ES256', 'HS256', 'HS384',
63+ * 'HS512', 'RS256', 'RS384', and 'RS512'
6264 *
6365 * @return object The JWT's payload as a PHP object
6466 *
@@ -102,8 +104,8 @@ public static function decode($jwt, $key, array $allowed_algs = array())
102104 if (!\in_array ($ header ->alg , $ allowed_algs )) {
103105 throw new UnexpectedValueException ('Algorithm not allowed ' );
104106 }
105- if ($ header ->alg === 'ES256 ' ) {
106- // OpenSSL expects an ASN.1 DER sequence for ES256 signatures
107+ if ($ header ->alg === 'ES256 ' || $ header -> alg === ' ES384 ' ) {
108+ // OpenSSL expects an ASN.1 DER sequence for ES256/ES384 signatures
107109 $ sig = self ::signatureToDER ($ sig );
108110 }
109111
@@ -155,7 +157,8 @@ public static function decode($jwt, $key, array $allowed_algs = array())
155157 * @param string $key The secret key.
156158 * If the algorithm used is asymmetric, this is the private key
157159 * @param string $alg The signing algorithm.
158- * Supported algorithms are 'ES256', 'HS256', 'HS384', 'HS512', 'RS256', 'RS384', and 'RS512'
160+ * Supported algorithms are 'ES384','ES256', 'HS256', 'HS384',
161+ * 'HS512', 'RS256', 'RS384', and 'RS512'
159162 * @param mixed $keyId
160163 * @param array $head An array with header elements to attach
161164 *
@@ -190,7 +193,8 @@ public static function encode($payload, $key, $alg = 'HS256', $keyId = null, $he
190193 * @param string $msg The message to sign
191194 * @param string|resource $key The secret key
192195 * @param string $alg The signing algorithm.
193- * Supported algorithms are 'ES256', 'HS256', 'HS384', 'HS512', 'RS256', 'RS384', and 'RS512'
196+ * Supported algorithms are 'ES384','ES256', 'HS256', 'HS384',
197+ * 'HS512', 'RS256', 'RS384', and 'RS512'
194198 *
195199 * @return string An encrypted message
196200 *
@@ -214,6 +218,9 @@ public static function sign($msg, $key, $alg = 'HS256')
214218 if ($ alg === 'ES256 ' ) {
215219 $ signature = self ::signatureFromDER ($ signature , 256 );
216220 }
221+ if ($ alg === 'ES384 ' ) {
222+ $ signature = self ::signatureFromDER ($ signature , 384 );
223+ }
217224 return $ signature ;
218225 }
219226 }
0 commit comments