use of com.nimbusds.jose.crypto.RSAEncrypter in project oxAuth by GluuFederation.
the class CrossEncryptionTest method encryptWithNimbusJoseJwt.
private String encryptWithNimbusJoseJwt() {
try {
RSAKey senderJWK = (RSAKey) JWK.parse(senderJwkJson);
RSAKey recipientPublicJWK = (RSAKey) (JWK.parse(recipientJwkJson));
// Create JWT
// SignedJWT signedJWT = new SignedJWT(
// new JWSHeader.Builder(JWSAlgorithm.RS256).keyID(senderJWK.getKeyID()).build(),
// new JWTClaimsSet.Builder()
// .subject("testi")
// .issuer("https:devgluu.saminet.local")
// .build());
// Sign the JWT
// signedJWT.sign(new RSASSASigner(senderJWK));
// Create JWE object with signed JWT as payload
// JWEObject jweObject = new JWEObject(
// new JWEHeader.Builder(JWEAlgorithm.RSA_OAEP, EncryptionMethod.A128GCM)
// .contentType("JWT") // required to indicate nested JWT
// .build(),
// new Payload(signedJWT));
@SuppressWarnings("deprecation") JWEObject jweObject = new JWEObject(new JWEHeader.Builder(JWEAlgorithm.RSA_OAEP, EncryptionMethod.A128GCM).type(JOSEObjectType.JWT).keyID(senderJWK.getKeyID()).build(), new Payload(Base64Util.base64urlencode(PAYLOAD.getBytes(Charsets.UTF_8))));
// Encrypt with the recipient's public key
RSAEncrypter encrypter = new RSAEncrypter(recipientPublicJWK);
jweObject.encrypt(encrypter);
// Serialise to JWE compact form
return jweObject.serialize();
} catch (Exception e) {
System.out.println("Error encryption with Nimbus: " + e.getMessage());
return null;
}
}
use of com.nimbusds.jose.crypto.RSAEncrypter in project oxAuth by GluuFederation.
the class CrossEncryptionTest method nestedJWT.
@Test
public void nestedJWT() throws Exception {
RSAKey senderJWK = (RSAKey) JWK.parse(senderJwkJson);
RSAKey recipientPublicJWK = (RSAKey) (JWK.parse(recipientJwkJson));
// Create JWT
SignedJWT signedJWT = new SignedJWT(new JWSHeader.Builder(JWSAlgorithm.RS256).keyID(senderJWK.getKeyID()).build(), new JWTClaimsSet.Builder().subject("testi").issuer("https:devgluu.saminet.local").build());
signedJWT.sign(new RSASSASigner(senderJWK));
JWEObject jweObject = new JWEObject(new JWEHeader.Builder(JWEAlgorithm.RSA_OAEP, EncryptionMethod.A128GCM).contentType(// required to indicate nested JWT
"JWT").build(), new Payload(signedJWT));
// Encrypt with the recipient's public key
RSAEncrypter encrypter = new RSAEncrypter(recipientPublicJWK);
jweObject.encrypt(encrypter);
final String jweString = jweObject.serialize();
decryptAndValidateSignatureWithGluu(jweString);
}
Aggregations