Developer
Developer

Reputation: 4321

Hide data from user Windows 8

i have a need to save some data to LocalStorage that user must not modify - so i need to hide or encode it. How can i do this?

Lets say i wan't to store earned point count when i'm in offline mode, but when i'm back online i wan't to send data to server. But if user will modify the file then the data will be incorrect.

I have tried to use, but some namespaces don't exist in 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);
}

Upvotes: 0

Views: 78

Answers (1)

dcastro
dcastro

Reputation: 68660

That code works on standard .NET, but not on .NET for Windows Store apps.

It seems .NET for Windows Store Apps simply does not have System.Security.Cryptography.RijndaelManaged.

The Windows.Security.Cryptography namespace only has one class: CryptographicBuffer.

You'll have to use SymmetricKeyAlgorithmProvider.OpenAlgorithm to choose a symmetric encryption algorithm. Here you'll find a list of all the symmetric algorithms supported on WinRT.

Upvotes: 3

Related Questions