我有一个包含大量敏感数据的大型 xml 文档。我有一个用 Rijndael 加密这些数据的算法。
byte[] encrypted;
using (RijndaelManaged rijAlg = new RijndaelManaged())
{
rijAlg.Key = EncyptionManager.RijndaelKey;
rijAlg.IV = EncyptionManager.RijndaelIV;
rijAlg.Padding = PaddingMode.PKCS7;
ICryptoTransform encryptor = rijAlg.CreateEncryptor(rijAlg.Key, rijAlg.IV);
using (MemoryStream msEncrypt = new MemoryStream())
{
using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
{
using (StreamWriter swEncrypt = new StreamWriter(csEncrypt))
{
swEncrypt.Write(plainText);
}
encrypted = msEncrypt.ToArray();
}
}
}
return encrypted;
假设绝大多数文件需要加密存储,是创建 xml 文档并加密文件的全部内容更有效,还是保持 xml 模式完整并仅加密特定字段?