Skip to content

Commit

Permalink
Fix pemEncodePublicKey (#2210)
Browse files Browse the repository at this point in the history
There were 2 version, one in KeyInfo, one in JsonWebKey
The version from JsonWebKey was with \r\n instead of only \n

Deleted the version from KeyInfo with PR #2118, fix this now.
Ensure that value entry in token_key is as before
  • Loading branch information
strehle committed Feb 28, 2023
1 parent 2932e30 commit 243adac
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.nimbusds.jose.HeaderParameterNames;
import com.nimbusds.jose.jwk.JWKParameterNames;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.BaseNCodec;

import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -47,6 +48,8 @@
@JsonSerialize(using = JsonWebKeySerializer.class)
public class JsonWebKey {

private static final java.util.Base64.Encoder base64encoder = java.util.Base64.getMimeEncoder(BaseNCodec.PEM_CHUNK_SIZE, "\n".getBytes());

// value is not defined in RFC 7517
public static final String PUBLIC_KEY_VALUE = "value";

Expand Down Expand Up @@ -155,7 +158,8 @@ public static String pemEncodePublicKey(PublicKey publicKey) {
String begin = "-----BEGIN PUBLIC KEY-----\n";
String end = "\n-----END PUBLIC KEY-----";
byte[] data = publicKey.getEncoded();
String base64encoded = new String(new Base64(false).encode(data));
String base64encoded = new String(base64encoder.encode(data));

return begin + base64encoded + end;
}

Expand Down

0 comments on commit 243adac

Please sign in to comment.