encryptedKey = Base64URL.encode(RSA_OAEP_256.encryptCEK(publicKey, cek, keyEncryptionProvider));
} else {
throw new JOSEException("Unsupported JWE algorithm, must be RSA1_5, RSA-OAEP, or RSA-OAEP-256");
}
// Apply compression if instructed
byte[] plainText = DeflateHelper.applyCompression(header, bytes);
// Compose the AAD
byte[] aad = StringUtils.toByteArray(header.toBase64URL().toString());
// Encrypt the plain text according to the JWE enc
byte[] iv;
AuthenticatedCipherText authCipherText;
if (enc.equals(EncryptionMethod.A128CBC_HS256) ||
enc.equals(EncryptionMethod.A192CBC_HS384) ||
enc.equals(EncryptionMethod.A256CBC_HS512) ) {
iv = AESCBC.generateIV(randomGen);
authCipherText = AESCBC.encryptAuthenticated(
cek, iv, plainText, aad,
contentEncryptionProvider, macProvider);
} else if (enc.equals(EncryptionMethod.A128GCM) ||
enc.equals(EncryptionMethod.A192GCM) ||
enc.equals(EncryptionMethod.A256GCM) ) {
iv = AESGCM.generateIV(randomGen);
authCipherText = AESGCM.encrypt(
cek, iv, plainText, aad,
contentEncryptionProvider);
} else if (enc.equals(EncryptionMethod.A128CBC_HS256_DEPRECATED) ||
enc.equals(EncryptionMethod.A256CBC_HS512_DEPRECATED) ) {
iv = AESCBC.generateIV(randomGen);
authCipherText = AESCBC.encryptWithConcatKDF(
header, cek, encryptedKey, iv, plainText,
contentEncryptionProvider, macProvider);
} else {
throw new JOSEException("Unsupported encryption method, must be A128CBC_HS256, A192CBC_HS384, A256CBC_HS512, A128GCM, A192GCM or A256GCM");
}
return new JWECryptoParts(encryptedKey,
Base64URL.encode(iv),
Base64URL.encode(authCipherText.getCipherText()),