I'm trying do to a program which stores many (5-15) .txt files in phone's isolated storage memory. I noticed how easy it is to read those files with programs like Windows Phone Power Tools so I decided to to encrypt them. I'm using this link as a tutorial:
http://msdn.microsoft.com/en-us/library/windows/apps/hh487164(v=vs.105).aspx
Encryption works fine, as I'm obviously saving one file at a time. However, I'm having problems while trying to decrypt them. How should i edit my code so I can decrypt many .txt files? Below are my codes that I'm using at the moment:
private void IsoRead()
{
System.IO.IsolatedStorage.IsolatedStorageFile local =
System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication();
string[] filenames = local.GetFileNames("./DataFolder/*.txt*");
foreach (var fname in filenames)
{
//retrieve byte
byte[] ProtectedByte = this.DecryptByte();
//decrypt with Unprotect method
byte[] FromByte = ProtectedData.Unprotect(ProtectedByte, null);
//convert from byte to string
fText = Encoding.UTF8.GetString(FromByte, 0, FromByte.Length);
this.Items.Add(new itemView() { LineOne = fname, LineTwo = fText });
}
}
And the other one:
private byte[] DecryptByte()
{
// Access the file in the application's isolated storage.
IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream readstream = new IsolatedStorageFileStream
("DataFolder\\"/*Here's where I'm having problems with*/, System.IO.FileMode.Open, FileAccess.Read, file);
// Read the written data from the file.
Stream reader = new StreamReader(readstream).BaseStream;
byte[] dataArray = new byte[reader.Length];
reader.Read(dataArray, 0, dataArray.Length);
return dataArray;
}
So basically the program has a listview page that get's the files from isolated storage. If one is touched, it goes to a new page that shows what's written in it.
Bonus question: Can I encrypt folders in WP7/WP8?
Edit: added one code line into IsoRead.