@@ -55,6 +55,7 @@ class JWT
55
55
public static $ supported_algs = [
56
56
'ES384 ' => ['openssl ' , 'SHA384 ' ],
57
57
'ES256 ' => ['openssl ' , 'SHA256 ' ],
58
+ 'ES256K ' => ['openssl ' , 'SHA256 ' ],
58
59
'HS256 ' => ['hash_hmac ' , 'SHA256 ' ],
59
60
'HS384 ' => ['hash_hmac ' , 'SHA384 ' ],
60
61
'HS512 ' => ['hash_hmac ' , 'SHA512 ' ],
@@ -132,8 +133,8 @@ public static function decode(
132
133
// See issue #351
133
134
throw new UnexpectedValueException ('Incorrect key for this algorithm ' );
134
135
}
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
137
138
$ sig = self ::signatureToDER ($ sig );
138
139
}
139
140
if (!self ::verify ("{$ headb64 }. {$ bodyb64 }" , $ sig , $ key ->getKeyMaterial (), $ header ->alg )) {
@@ -170,8 +171,8 @@ public static function decode(
170
171
*
171
172
* @param array<mixed> $payload PHP array
172
173
* @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'
175
176
* @param string $keyId
176
177
* @param array<string, string> $head An array with header elements to attach
177
178
*
@@ -210,8 +211,8 @@ public static function encode(
210
211
*
211
212
* @param string $msg The message to sign
212
213
* @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'
215
216
*
216
217
* @return string An encrypted message
217
218
*
@@ -238,7 +239,7 @@ public static function sign(
238
239
if (!$ success ) {
239
240
throw new DomainException ('OpenSSL unable to sign data ' );
240
241
}
241
- if ($ alg === 'ES256 ' ) {
242
+ if ($ alg === 'ES256 ' || $ alg === ' ES256K ' ) {
242
243
$ signature = self ::signatureFromDER ($ signature , 256 );
243
244
} elseif ($ alg === 'ES384 ' ) {
244
245
$ signature = self ::signatureFromDER ($ signature , 384 );
0 commit comments