We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent e41f1bd commit b4c78aaCopy full SHA for b4c78aa
1 file changed
src/JWK.php
@@ -240,6 +240,14 @@ private static function createPemFromModulusAndExponent(
240
): string {
241
$mod = JWT::urlsafeB64Decode($n);
242
$exp = JWT::urlsafeB64Decode($e);
243
+ // Correct encoding for ASN1, as ints are represented as unsigned in jwk
244
+ // but signed in ASN1. Prepending null byte makes it unsigned.
245
+ if (\strlen($mod) > 0 && \ord($mod[0]) >= 128) {
246
+ $mod = \chr(0) . $mod;
247
+ }
248
+ if (\strlen($exp) > 0 && \ord($exp[0]) >= 128) {
249
+ $exp = \chr(0) . $exp;
250
251
252
$modulus = \pack('Ca*a*', 2, self::encodeLength(\strlen($mod)), $mod);
253
$publicExponent = \pack('Ca*a*', 2, self::encodeLength(\strlen($exp)), $exp);
0 commit comments