我需要将一些用户不能修改的数据保存到LocalStorage,所以我需要隐藏或对其进行编码。我该怎么做?
让我说,当我处于离线模式时,我不会存储挣来的点数,但当我回到在线时,我不会将数据发送到服务器。但是,如果用户将修改文件,那么数据将是不正确的。
我试过使用,但Windows 8中不存在一些名称空间:
public static string Encrypt(string plainText)
{
byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText);
byte[] keyBytes = new Rfc2898DeriveBytes(PasswordHash, Encoding.ASCII.GetBytes(SaltKey)).GetBytes(256 / 8);
var symmetricKey = new RijndaelManaged() { Mode = CipherMode.CBC, Padding = PaddingMode.Zeros };
var encryptor = symmetricKey.CreateEncryptor(keyBytes, Encoding.ASCII.GetBytes(VIKey));
byte[] cipherTextBytes;
using (var memoryStream = new MemoryStream())
{
using (var cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write))
{
cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length);
cryptoStream.FlushFinalBlock();
cipherTextBytes = memoryStream.ToArray();
cryptoStream.Close();
}
memoryStream.Close();
}
return Convert.ToBase64String(cipherTextBytes);
}发布于 2014-03-26 11:48:21
该代码适用于标准.NET,但不适用于Windows应用程序的.NET。
看来,Windows的.NET应用程序根本没有System.Security.Cryptography.RijndaelManaged。
命名空间只有一个类:CryptographicBuffer。
您必须使用SymmetricKeyAlgorithmProvider.OpenAlgorithm来选择对称加密算法。这里,您将找到WinRT支持的所有对称算法的列表。
https://stackoverflow.com/questions/22659876
复制相似问题