Search in sources :

Example 1 with DirectDecrypter

use of com.nimbusds.jose.crypto.DirectDecrypter in project perry by ca-cwds.

the class JwtService method decrypt.

private SignedJWT decrypt(String token) throws JwtException {
    try {
        SignedJWT signedJWT;
        JWEObject jweObject = JWEObject.parse(token);
        jweObject.decrypt(new DirectDecrypter(keyProvider.getEncryptingKey().getEncoded()));
        signedJWT = jweObject.getPayload().toSignedJWT();
        return signedJWT;
    } catch (Exception e) {
        throw new JwtException(e);
    }
}
Also used : JWEObject(com.nimbusds.jose.JWEObject) SignedJWT(com.nimbusds.jwt.SignedJWT) DirectDecrypter(com.nimbusds.jose.crypto.DirectDecrypter) GeneralSecurityException(java.security.GeneralSecurityException)

Example 2 with DirectDecrypter

use of com.nimbusds.jose.crypto.DirectDecrypter in project gravitee-management-rest-api by gravitee-io.

the class ReferenceSerializer method deserialize.

public IdentityReference deserialize(String token) throws Exception {
    String sToken = new String(Base64.getDecoder().decode(token));
    // Parse the JWE string
    JWEObject jweObject = JWEObject.parse(sToken);
    // Decrypt with shared key
    jweObject.decrypt(new DirectDecrypter(secretKey.getEncoded()));
    // Extract payload
    SignedJWT signedJWT = jweObject.getPayload().toSignedJWT();
    // Check the HMAC
    signedJWT.verify(new MACVerifier(secretKey.getEncoded()));
    // Retrieve the JWT claims
    return new IdentityReference(signedJWT.getJWTClaimsSet().getIssuer(), signedJWT.getJWTClaimsSet().getSubject());
}
Also used : IdentityReference(io.gravitee.management.idp.api.identity.IdentityReference) MACVerifier(com.nimbusds.jose.crypto.MACVerifier) DirectDecrypter(com.nimbusds.jose.crypto.DirectDecrypter) SignedJWT(com.nimbusds.jwt.SignedJWT)

Aggregations

DirectDecrypter (com.nimbusds.jose.crypto.DirectDecrypter)2 SignedJWT (com.nimbusds.jwt.SignedJWT)2 JWEObject (com.nimbusds.jose.JWEObject)1 MACVerifier (com.nimbusds.jose.crypto.MACVerifier)1 IdentityReference (io.gravitee.management.idp.api.identity.IdentityReference)1 GeneralSecurityException (java.security.GeneralSecurityException)1