我曾尝试在我的 xml 中实现自动加密和解密,但它不只是工作,即数据未加密。可能是什么原因?我的代码如下所示。我正在使用XmlSerializer
类。谢谢
[Serializable]
public class User
{
public string _username;
public string _password;
public string[] _roles;
[XmlIgnore]
public string Username
{
get { return _username; }
set { _username = value; }
}
[XmlIgnore]
public string Password
{
get { return _password; }
set { _password = value; }
}
[XmlIgnore]
public string[] Roles
{
get { return _roles; }
set { _roles = value; }
}
[OnDeserializingAttribute]
internal void DecryptPersonalData(StreamingContext context)
{
_username = Crypto.Decrypt(_username);
_password = Crypto.Decrypt(_password);
for (int i = 0; i < _roles.Length; i++)
{
_roles[i] = Crypto.Decrypt(_roles[i]);
}
}
[OnSerializingAttribute]
internal void EncryptPersonalData(StreamingContext context)
{
_username = Crypto.Encrypt(_username);
_password = Crypto.Encrypt(_password);
for (int i = 0; i < _roles.Length; i++)
{
_roles[i] = Crypto.Encrypt(_roles[i]);
}
}
}