我有一个DataSet
,我在加密模式的xml
文件中序列化。
目前正在srinivasganaparthi关注以加密模式创建xml
。我也想把文件作为只读文件。为达到这个。我正在尝试这个:
public static void EncryptAndSerialize(Object obj)
{
UnicodeEncoding aUE = new UnicodeEncoding();
byte[] key = aUE.GetBytes("password");
RijndaelManaged RMCrypto = new RijndaelManaged();
using (FileStream fs = File.Open(@"D:\Sample.xml", FileMode.Create))
{
using (CryptoStream cs = new CryptoStream(fs, RMCrypto.CreateEncryptor(key, key), CryptoStreamMode.Write))
{
XmlSerializer xmlser = new XmlSerializer(obj.GetType());
xmlser.Serialize(cs, obj);
}
fs.Close();
File.SetAttributes(@"D:\Sample.xml",FileAttributes.ReadOnly);
}
但File.SetAttributes
似乎无效。我怎么能只读这个?