Security helper class that encrypt/decrypt settings and files

Even though the Windows Phone platform is more secure than either iOS or Android, it is always good practice to encrypt sensitive data.

I created a small SecurityHelper class that handles the encryption and the decryption of application settings and files.

The usage of the class is easy as:

SecurityHelper.WriteSetting("Username", "Sébastien");

string username = SecurityHelper.ReadSetting("Username");

The complete usage is described in the following sample code (which is also available in the downloadable Sample project below):

using System.Diagnostics;
using DotNetApp;

namespace SecurityHelperApp
{
    public partial class MainPage
    {
        public MainPage()
        {
            InitializeComponent();

            // Write and read an ApplicationSetting into the IsolatedStorageSettings
            WriteReadSettingExample();

            // Write and read a file with the specified string content
            WriteReadFileWithStringContentExample();

            // Write and read a file in a sub folder with the specified string content
            WriteReadFileInSubFolderWithStringContentExample();

            // Write and read a file with the specified bytes content
            WriteReadFileWithByteContentExample();
        }

        #region Private Methods

        private void WriteReadSettingExample()
        {
            SecurityHelper.WriteSetting("Username", "Sébastien");

            string username = SecurityHelper.ReadSetting("Username");

            Debug.Assert(username == "Sébastien");
        }

        private void WriteReadFileWithStringContentExample()
        {
            SecurityHelper.WriteFile("File1.txt", "I love Windows Phone");

            string content = SecurityHelper.ReadFile("File1.txt");

            Debug.Assert(content == "I love Windows Phone");
        }

        private void WriteReadFileInSubFolderWithStringContentExample()
        {
            SecurityHelper.WriteFile("Metro/SubFolder/File3.txt", "I love the Metro design");

            string content = SecurityHelper.ReadFile("Metro/SubFolder/File3.txt");

            Debug.Assert(content == "I love the Metro design");
        }

        private void WriteReadFileWithByteContentExample()
        {
            byte[] content = new byte[] {1, 2, 3, 4, 5};
            SecurityHelper.WriteFile("File2.txt", content);

            byte[] readContent;
            SecurityHelper.ReadFile("File2.txt", out readContent);

            Debug.Assert(content[0] == readContent[0] && content[1] == readContent[1] && content[2] == readContent[2] && 
                content[3] == readContent[3] && content[4] == readContent[4]);
        }

        #endregion
    }
}

Download SecurityHelper
Download Sample project