Search in sources :

Example 6 with KeyEncryptionAlgorithm

use of org.gluu.oxauth.model.crypto.encryption.KeyEncryptionAlgorithm in project oxAuth by GluuFederation.

the class CrossEncryptionTest method encryptWithGluuJweEncrypter.

private String encryptWithGluuJweEncrypter() {
    try {
        RSAKey recipientPublicJWK = (RSAKey) (JWK.parse(recipientJwkJson));
        BlockEncryptionAlgorithm blockEncryptionAlgorithm = BlockEncryptionAlgorithm.A128GCM;
        KeyEncryptionAlgorithm keyEncryptionAlgorithm = KeyEncryptionAlgorithm.RSA_OAEP;
        Jwe jwe = new Jwe();
        jwe.getHeader().setType(JwtType.JWT);
        jwe.getHeader().setAlgorithm(keyEncryptionAlgorithm);
        jwe.getHeader().setEncryptionMethod(blockEncryptionAlgorithm);
        jwe.getClaims().setIssuer("https:devgluu.saminet.local");
        jwe.getClaims().setSubjectIdentifier("testing");
        jwe.getHeader().setKeyId("1");
        JweEncrypterImpl encrypter = new JweEncrypterImpl(keyEncryptionAlgorithm, blockEncryptionAlgorithm, recipientPublicJWK.toPublicKey());
        jwe = encrypter.encrypt(jwe);
        // System.out.println("EncodedIntegrityValue: " + jwe.getEncodedIntegrityValue());
        return jwe.toString();
    } catch (Exception e) {
        System.out.println("Error encryption with Gluu JweEncrypter: " + e.getMessage());
        return null;
    }
}
Also used : RSAKey(com.nimbusds.jose.jwk.RSAKey) KeyEncryptionAlgorithm(org.gluu.oxauth.model.crypto.encryption.KeyEncryptionAlgorithm) Jwe(org.gluu.oxauth.model.jwe.Jwe) JweEncrypterImpl(org.gluu.oxauth.model.jwe.JweEncrypterImpl) 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) BlockEncryptionAlgorithm(org.gluu.oxauth.model.crypto.encryption.BlockEncryptionAlgorithm)

Aggregations

KeyEncryptionAlgorithm (org.gluu.oxauth.model.crypto.encryption.KeyEncryptionAlgorithm)6 InvalidJweException (org.gluu.oxauth.model.exception.InvalidJweException)6 BlockEncryptionAlgorithm (org.gluu.oxauth.model.crypto.encryption.BlockEncryptionAlgorithm)5 InvalidJwtException (org.gluu.oxauth.model.exception.InvalidJwtException)3 Jwe (org.gluu.oxauth.model.jwe.Jwe)3 JweEncrypterImpl (org.gluu.oxauth.model.jwe.JweEncrypterImpl)3 Jwt (org.gluu.oxauth.model.jwt.Jwt)3 RSAKey (com.nimbusds.jose.jwk.RSAKey)2 IOException (java.io.IOException)2 PrivateKey (java.security.PrivateKey)2 ParseException (java.text.ParseException)2 SignatureAlgorithm (org.gluu.oxauth.model.crypto.signature.SignatureAlgorithm)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 JWEDecrypter (com.nimbusds.jose.JWEDecrypter)1 EncryptedJWT (com.nimbusds.jwt.EncryptedJWT)1 SignedJWT (com.nimbusds.jwt.SignedJWT)1 Key (java.security.Key)1 MessageDigest (java.security.MessageDigest)1 PublicKey (java.security.PublicKey)1