throw new RuntimeException("The authentication tag must not be null");
}
// Derive the content encryption key
Algorithm alg = readOnlyJWEHeader.getAlgorithm();
SecretKey cek = null;
byte[] encryptedKey = Base64Url.decode(encodedEncryptedKey);
byte[] aad = encodedHeader.getBytes(Charset.forName("UTF-8"));
byte[] iv = Base64Url.decode(encodedIv);
byte[] cipherText = Base64Url.decode(encodedCipherText);
byte[] authTag = Base64Url.decode(encodedAuthTag);
if (alg.equals(Algorithm.RSA1_5))
{
int keyLength = readOnlyJWEHeader.getEncryptionMethod().getCekBitLength();
SecretKey randomCEK = AES.generateKey(keyLength);
try
{
cek = RSA1_5.decryptCEK(privateKey, encryptedKey, keyLength);
}
catch (Exception e)
{
// Protect against MMA attack by generating random CEK on failure,
// see http://www.ietf.org/mail-archive/web/jose/current/msg01832.html
cek = randomCEK;
}
}
else if (alg.equals(Algorithm.RSA_OAEP))
{
cek = RSA_OAEP.decryptCEK(privateKey, encryptedKey);
}