Search in sources :

Example 1 with JweDecrypterImpl

use of org.gluu.oxauth.model.jwe.JweDecrypterImpl in project oxAuth by GluuFederation.

the class CrossEncryptionTest method testDecryptWithGluuDecrypter.

public boolean testDecryptWithGluuDecrypter(String jwe) {
    try {
        JWK jwk = JWK.parse(recipientJwkJson);
        RSAPrivateKey rsaPrivateKey = ((RSAKey) jwk).toRSAPrivateKey();
        JweDecrypterImpl decrypter = new JweDecrypterImpl(rsaPrivateKey);
        decrypter.setKeyEncryptionAlgorithm(KeyEncryptionAlgorithm.RSA_OAEP);
        decrypter.setBlockEncryptionAlgorithm(BlockEncryptionAlgorithm.A128GCM);
        final String decryptedPayload = decrypter.decrypt(jwe).getClaims().toJsonString().toString();
        System.out.println("Gluu decrypt succeed: " + decryptedPayload);
        if (isJsonEqual(decryptedPayload, PAYLOAD)) {
            return true;
        }
    } catch (Exception e) {
        System.out.println("Gluu decrypt failed: " + e.getMessage());
        e.printStackTrace();
    }
    return false;
}
Also used : RSAKey(com.nimbusds.jose.jwk.RSAKey) JweDecrypterImpl(org.gluu.oxauth.model.jwe.JweDecrypterImpl) RSAPrivateKey(java.security.interfaces.RSAPrivateKey) JSONException(org.json.JSONException) ParseException(java.text.ParseException) InvalidJwtException(org.gluu.oxauth.model.exception.InvalidJwtException) IOException(java.io.IOException) InvalidJweException(org.gluu.oxauth.model.exception.InvalidJweException) JWK(com.nimbusds.jose.jwk.JWK)

Example 2 with JweDecrypterImpl

use of org.gluu.oxauth.model.jwe.JweDecrypterImpl in project oxAuth by GluuFederation.

the class CrossEncryptionTest method decryptAndValidateSignatureWithGluu.

private void decryptAndValidateSignatureWithGluu(String jweString) throws ParseException, JOSEException, InvalidJweException, JSONException, InvalidJwtException {
    JWK jwk = JWK.parse(recipientJwkJson);
    RSAPrivateKey rsaPrivateKey = ((RSAKey) jwk).toRSAPrivateKey();
    JweDecrypterImpl decrypter = new JweDecrypterImpl(rsaPrivateKey);
    decrypter.setKeyEncryptionAlgorithm(KeyEncryptionAlgorithm.RSA_OAEP);
    decrypter.setBlockEncryptionAlgorithm(BlockEncryptionAlgorithm.A128GCM);
    final Jwe jwe = decrypter.decrypt(jweString);
    assertEquals(JwtType.JWT, jwe.getHeader().getContentType());
    final Jwt jwt = jwe.getSignedJWTPayload();
    Assert.assertTrue(new RSASigner(SignatureAlgorithm.RS256, getSenderPublicKey()).validate(jwt));
    System.out.println("Gluu decrypt and nested jwt signature verification succeed: " + jwt.getClaims().toJsonString());
}
Also used : RSAKey(com.nimbusds.jose.jwk.RSAKey) JweDecrypterImpl(org.gluu.oxauth.model.jwe.JweDecrypterImpl) Jwt(org.gluu.oxauth.model.jwt.Jwt) RSASigner(org.gluu.oxauth.model.jws.RSASigner) Jwe(org.gluu.oxauth.model.jwe.Jwe) RSAPrivateKey(java.security.interfaces.RSAPrivateKey) JWK(com.nimbusds.jose.jwk.JWK)

Aggregations

JWK (com.nimbusds.jose.jwk.JWK)2 RSAKey (com.nimbusds.jose.jwk.RSAKey)2 RSAPrivateKey (java.security.interfaces.RSAPrivateKey)2 JweDecrypterImpl (org.gluu.oxauth.model.jwe.JweDecrypterImpl)2 IOException (java.io.IOException)1 ParseException (java.text.ParseException)1 InvalidJweException (org.gluu.oxauth.model.exception.InvalidJweException)1 InvalidJwtException (org.gluu.oxauth.model.exception.InvalidJwtException)1 Jwe (org.gluu.oxauth.model.jwe.Jwe)1 RSASigner (org.gluu.oxauth.model.jws.RSASigner)1 Jwt (org.gluu.oxauth.model.jwt.Jwt)1 JSONException (org.json.JSONException)1