use of com.nimbusds.jose.crypto.DirectEncrypter in project perry by ca-cwds.
the class JwtService method encrypt.
private JWEObject encrypt(SignedJWT signedJWT) throws JwtException {
try {
JWEObject jweObject = new JWEObject(jweHeader(), new Payload(signedJWT));
jweObject.encrypt(new DirectEncrypter(keyProvider.getEncryptingKey().getEncoded()));
return jweObject;
} catch (Exception e) {
throw new JwtException(e);
}
}
use of com.nimbusds.jose.crypto.DirectEncrypter in project gravitee-management-rest-api by gravitee-io.
the class ReferenceSerializer method serialize.
public String serialize(IdentityReference reference) throws Exception {
// Create HMAC signer
JWSSigner signer = new MACSigner(secretKey.getEncoded());
// Prepare JWT with claims set
JWTClaimsSet claimsSet = new JWTClaimsSet.Builder().subject(reference.getReference()).issuer(reference.getSource()).build();
SignedJWT signedJWT = new SignedJWT(new JWSHeader(JWSAlgorithm.HS256), claimsSet);
// Apply the HMAC protection
signedJWT.sign(signer);
// Create JWE object with signed JWT as payload
JWEObject jweObject = new JWEObject(new JWEHeader.Builder(JWEAlgorithm.DIR, EncryptionMethod.A256GCM).contentType(// required to signal nested JWT
"JWT").build(), new Payload(signedJWT));
// Perform encryption
jweObject.encrypt(new DirectEncrypter(secretKey.getEncoded()));
// Serialize to compact form
return new String(Base64.getEncoder().encode(jweObject.serialize().getBytes()));
}
Aggregations