提交 379afcdd 编写于 作者: 智布道's avatar 智布道 👁

🐛 Fix a bug of JwkUtil

上级 e64a8cce
......@@ -21,6 +21,7 @@ import org.jose4j.jwk.*;
import org.jose4j.keys.EllipticCurves;
import org.jose4j.lang.JoseException;
import java.security.spec.ECParameterSpec;
import java.util.Arrays;
/**
......@@ -46,9 +47,9 @@ public class JwkUtil {
RsaJsonWebKey jwk = null;
try {
jwk = RsaJwkGenerator.generateJwk(2048);
jwk.setUse(Use.SIGNATURE);
jwk.setKeyId(keyId);
jwk.setAlgorithm(signingAlg.getAlg());
jwk.setUse("sig");
} catch (JoseException e) {
e.printStackTrace();
throw new InvalidJwksException("Unable to create RSA Json Web Key.");
......@@ -92,12 +93,21 @@ public class JwkUtil {
throw new InvalidJwksException("Unable to create ES Json Web Key. Unsupported jwk algorithm, only supports ES256, ES384, ES512");
}
EllipticCurveJsonWebKey jwk = null;
ECParameterSpec spec = null;
if (signingAlg == TokenSigningAlg.ES256) {
spec = EllipticCurves.P256;
} else if (signingAlg == TokenSigningAlg.ES384) {
spec = EllipticCurves.P384;
} else {
spec = EllipticCurves.P521;
}
try {
jwk = EcJwkGenerator.generateJwk(EllipticCurves.P256);
jwk = EcJwkGenerator.generateJwk(spec);
jwk.setUse(Use.SIGNATURE);
jwk.setKeyId(keyId);
jwk.setAlgorithm(signingAlg.getAlg());
jwk.setUse("sig");
} catch (JoseException e) {
e.printStackTrace();
throw new InvalidJwksException("Unable to create ES Json Web Key.");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册