|
25 | 25 | import com.auth0.jwt.algorithms.CipherParams; |
26 | 26 | import com.auth0.jwt.exceptions.JWTDecodeException; |
27 | 27 | import com.auth0.jwt.exceptions.JWTVerificationException; |
| 28 | +import com.auth0.jwt.exceptions.KeyAgreementException; |
28 | 29 | import com.auth0.jwt.exceptions.oicmsg_exceptions.DeserializationNotPossible; |
29 | 30 | import com.auth0.jwt.exceptions.oicmsg_exceptions.JWKException; |
30 | 31 | import com.auth0.jwt.exceptions.oicmsg_exceptions.SerializationNotPossible; |
@@ -491,10 +492,14 @@ public String toJwt(Key signingKey, String alg, Key transportKey, String encAlg, |
491 | 492 | "encAlg and encEnc are mandatory parameters if transport key is set"); |
492 | 493 | } |
493 | 494 | try { |
494 | | - return JWTEncryptor.init().withPayload(signedJwt.getBytes("UTF-8")).encrypt( |
495 | | - AlgorithmResolver.resolveKeyTransportAlgorithmForEncryption(transportKey, encAlg, encEnc, keyjar, sender, receiver), |
496 | | - Algorithm.getContentEncryptionAlg(encEnc, CipherParams.getInstance(encEnc))); |
497 | | - } catch (UnsupportedEncodingException | ValueError | SerializationNotPossible e) { |
| 495 | + Algorithm keyTransportAlgorithm = AlgorithmResolver.resolveKeyTransportAlgorithmForEncryption( |
| 496 | + transportKey, encAlg, encEnc, keyjar, sender, receiver); |
| 497 | + Algorithm contentEncryptionAlgorithm = AlgorithmResolver |
| 498 | + .resolveContentEncryptionAlg(keyTransportAlgorithm, encEnc); |
| 499 | + return JWTEncryptor.init().withPayload(signedJwt.getBytes("UTF-8")) |
| 500 | + .encrypt(keyTransportAlgorithm, contentEncryptionAlgorithm); |
| 501 | + } catch (UnsupportedEncodingException | ValueError | SerializationNotPossible |
| 502 | + | KeyAgreementException e) { |
498 | 503 | throw new SerializationException( |
499 | 504 | String.format("Not able to initialize key transport algorithm '%s' to encrypt JWS, '%s'", |
500 | 505 | encAlg, e.getMessage())); |
|
0 commit comments