@@ -55,6 +55,7 @@ class JWT
5555 public static $ supported_algs = [
5656 'ES384 ' => ['openssl ' , 'SHA384 ' ],
5757 'ES256 ' => ['openssl ' , 'SHA256 ' ],
58+ 'ES256K ' => ['openssl ' , 'SHA256 ' ],
5859 'HS256 ' => ['hash_hmac ' , 'SHA256 ' ],
5960 'HS384 ' => ['hash_hmac ' , 'SHA384 ' ],
6061 'HS512 ' => ['hash_hmac ' , 'SHA512 ' ],
@@ -132,8 +133,8 @@ public static function decode(
132133 // See issue #351
133134 throw new UnexpectedValueException ('Incorrect key for this algorithm ' );
134135 }
135- if ($ header ->alg === 'ES256 ' || $ header -> alg === 'ES384 ' ) {
136- // OpenSSL expects an ASN.1 DER sequence for ES256/ES384 signatures
136+ if (\in_array ( $ header ->alg , [ 'ES256 ' , ' ES256K ' , 'ES384 ' ], true ) ) {
137+ // OpenSSL expects an ASN.1 DER sequence for ES256/ES256K/ ES384 signatures
137138 $ sig = self ::signatureToDER ($ sig );
138139 }
139140 if (!self ::verify ("{$ headb64 }. {$ bodyb64 }" , $ sig , $ key ->getKeyMaterial (), $ header ->alg )) {
@@ -170,8 +171,8 @@ public static function decode(
170171 *
171172 * @param array<mixed> $payload PHP array
172173 * @param string|resource|OpenSSLAsymmetricKey|OpenSSLCertificate $key The secret key.
173- * @param string $alg Supported algorithms are 'ES384','ES256', 'HS256 ', 'HS384 ',
174- * 'HS512', 'RS256', 'RS384', and 'RS512'
174+ * @param string $alg Supported algorithms are 'ES384','ES256', 'ES256K ', 'HS256 ',
175+ * 'HS384', ' HS512', 'RS256', 'RS384', and 'RS512'
175176 * @param string $keyId
176177 * @param array<string, string> $head An array with header elements to attach
177178 *
@@ -210,8 +211,8 @@ public static function encode(
210211 *
211212 * @param string $msg The message to sign
212213 * @param string|resource|OpenSSLAsymmetricKey|OpenSSLCertificate $key The secret key.
213- * @param string $alg Supported algorithms are 'ES384','ES256', 'HS256 ', 'HS384 ',
214- * 'HS512', 'RS256', 'RS384', and 'RS512'
214+ * @param string $alg Supported algorithms are 'ES384','ES256', 'ES256K ', 'HS256 ',
215+ * 'HS384', ' HS512', 'RS256', 'RS384', and 'RS512'
215216 *
216217 * @return string An encrypted message
217218 *
@@ -238,7 +239,7 @@ public static function sign(
238239 if (!$ success ) {
239240 throw new DomainException ('OpenSSL unable to sign data ' );
240241 }
241- if ($ alg === 'ES256 ' ) {
242+ if ($ alg === 'ES256 ' || $ alg === ' ES256K ' ) {
242243 $ signature = self ::signatureFromDER ($ signature , 256 );
243244 } elseif ($ alg === 'ES384 ' ) {
244245 $ signature = self ::signatureFromDER ($ signature , 384 );
0 commit comments