@Override public void decrypt(final EncryptedJWT encryptedJWT) throws JOSEException { init(); // decrypt encryptedJWT.decrypt(buildDecrypter()); }
@Override public String encrypt(final JWT jwt) { init(); if (jwt instanceof SignedJWT) { // Create JWE object with signed JWT as payload final JWEObject jweObject = new JWEObject( new JWEHeader.Builder(this.algorithm, this.method).contentType("JWT").build(), new Payload((SignedJWT) jwt)); try { // Perform encryption jweObject.encrypt(buildEncrypter()); } catch (final JOSEException e) { throw new TechnicalException(e); } // Serialise to JWE compact form return jweObject.serialize(); } else { // create header final JWEHeader header = new JWEHeader(this.algorithm, this.method); try { // encrypted jwt EncryptedJWT encryptedJwt = new EncryptedJWT(header, jwt.getJWTClaimsSet()); // Perform encryption encryptedJwt.encrypt(buildEncrypter()); // serialize return encryptedJwt.serialize(); } catch (final JOSEException | ParseException e) { throw new TechnicalException(e); } } }