EncryptedKey ek = encryptedData.getKeyInfo().itemEncryptedKey(0);
if (ek != null) {
XMLCipher keyCipher = XMLCipher.getInstance();
keyCipher.init(XMLCipher.UNWRAP_MODE, kek);
key = keyCipher.decryptKey(ek, encryptedData.getEncryptionMethod().getAlgorithm());
}
// Create a new cipher just to be paranoid
XMLCipher cipher3 = XMLCipher.getInstance();
cipher3.init(XMLCipher.DECRYPT_MODE, key);