Skip to content

Commit

Permalink
fix(did): base64Url encoding for keys
Browse files Browse the repository at this point in the history
  • Loading branch information
Torsten Egenolf committed Jun 6, 2024
1 parent a9b3294 commit 76b14e2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ public static class EcPublicKeyJwk extends PublicKeyJwk {
*/
public EcPublicKeyJwk(ECPublicKey ecPublicKey, List<String> base64EncodedCertificates) {
super("EC", base64EncodedCertificates);
valueX = Base64.getEncoder().encodeToString(ecPublicKey.getW().getAffineX().toByteArray());
valueY = Base64.getEncoder().encodeToString(ecPublicKey.getW().getAffineY().toByteArray());
valueX = Base64.getUrlEncoder().encodeToString(ecPublicKey.getW().getAffineX().toByteArray());
valueY = Base64.getUrlEncoder().encodeToString(ecPublicKey.getW().getAffineY().toByteArray());

ECNamedCurveSpec curveSpec = (ECNamedCurveSpec) ecPublicKey.getParams();
switch (curveSpec.getName()) {
Expand Down Expand Up @@ -113,8 +113,8 @@ public static class RsaPublicKeyJwk extends PublicKeyJwk {
*/
public RsaPublicKeyJwk(RSAPublicKey rsaPublicKey, List<String> base64EncodedCertificates) {
super("RSA", base64EncodedCertificates);
valueN = Base64.getEncoder().encodeToString(rsaPublicKey.getModulus().toByteArray());
valueE = Base64.getEncoder().encodeToString(rsaPublicKey.getPublicExponent().toByteArray());
valueN = Base64.getUrlEncoder().encodeToString(rsaPublicKey.getModulus().toByteArray());
valueE = Base64.getUrlEncoder().encodeToString(rsaPublicKey.getPublicExponent().toByteArray());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,17 +516,17 @@ private void assertVerificationMethod(Object in, String kid, X509Certificate dsc

if (dsc.getPublicKey().getAlgorithm().equals(CertificateTestUtils.SignerType.EC.getSigningAlgorithm())) {
Assertions.assertEquals(((ECPublicKey) dsc.getPublicKey()).getW().getAffineX(),
new BigInteger(Base64.getDecoder().decode(publicKeyJwk.get("x").toString())));
new BigInteger(Base64.getUrlDecoder().decode(publicKeyJwk.get("x").toString())));
Assertions.assertEquals(((ECPublicKey) dsc.getPublicKey()).getW().getAffineY(),
new BigInteger(Base64.getDecoder().decode(publicKeyJwk.get("y").toString())));
new BigInteger(Base64.getUrlDecoder().decode(publicKeyJwk.get("y").toString())));
Assertions.assertEquals(CertificateTestUtils.SignerType.EC.getSigningAlgorithm(),
publicKeyJwk.get("kty").toString());
Assertions.assertEquals("P-256", publicKeyJwk.get("crv").toString());
} else {
Assertions.assertEquals(((RSAPublicKey) dsc.getPublicKey()).getPublicExponent(),
new BigInteger(Base64.getDecoder().decode(publicKeyJwk.get("e").toString())));
new BigInteger(Base64.getUrlDecoder().decode(publicKeyJwk.get("e").toString())));
Assertions.assertEquals(((RSAPublicKey) dsc.getPublicKey()).getModulus(),
new BigInteger(Base64.getDecoder().decode(publicKeyJwk.get("n").toString())));
new BigInteger(Base64.getUrlDecoder().decode(publicKeyJwk.get("n").toString())));
Assertions.assertEquals(CertificateTestUtils.SignerType.RSA.getSigningAlgorithm(),
publicKeyJwk.get("kty").toString());
}
Expand Down

0 comments on commit 76b14e2

Please sign in to comment.