2014-03-26 25 views
0

我需要將一些數據保存到LocalStorage,用戶不得修改 - 所以我需要隱藏或編碼它。我怎樣才能做到這一點?隱藏用戶Windows 8的數據

假設我不想在離線模式下存儲贏得點數,但是當我回到線上時,我不想將數據發送到服務器。但是,如果用戶將修改文件,那麼數據將不正確。

我曾嘗試使用,但有些命名空間不能在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); 
} 
+0

你可以通過「一些名稱空間不存在」更具體嗎? 還檢查你是否有所有需要包括。 – nexno

回答

3

該代碼工作在標準的.NET,但不能在.NET的Windows Store應用程序。

看來.NET for Windows商店應用程序根本沒有System.Security.Cryptography.RijndaelManaged

Windows.Security.Cryptography namespace只有一個類:CryptographicBuffer

您必須使用SymmetricKeyAlgorithmProvider.OpenAlgorithm來選擇對稱加密算法。 Here您可以找到WinRT支持的所有對稱算法的列表。