EncryptedXml.EncryptData是否使用经过身份验证的加密? 我使用此算法标识符http://www.w3.org/2001/04/xmlenc#aes256-cbc。
我知道aes256-cbc
未通过身份验证,但是System.Security.Cryptography.Xml.EncryptedXml
会进行身份验证吗?
如果没有,当我使用例如HMAC-SHA-512
,如何在XmlDocument中传递此值?
http://www.w3.org/2001/04/xmlenc#rsa-1_5在经过身份验证的加密范围内是否不同?
public byte[] Encrypt(byte[] data, byte[] key)
{
using (var symmetricAlgorithm = new RijndaelManaged())
{
symmetricAlgorithm.Key = key;
var xmlDocument = new XmlDocument();
var dataElement = xmlDocument.CreateElement("Data");
dataElement.InnerText = Convert.ToBase64String(data);
xmlDocument.AppendChild(dataElement);
var encryptedElementData = (new EncryptedXml()).EncryptData(dataElement, symmetricAlgorithm, false);
var encryptedData = new EncryptedData
{
Type = EncryptedXml.XmlEncElementUrl,
EncryptionMethod = new EncryptionMethod(EncryptedXml.XmlEncAES256Url),
CipherData = { CipherValue = encryptedElementData }
};
EncryptedXml.ReplaceElement(dataElement, encryptedData, false);
using (var encryptedXmlStream = new MemoryStream())
{
xmlDocument.Save(encryptedXmlStream);
return encryptedXmlStream.ToArray();
}
}
}