Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

(Difference between revisions)

Compiling and using SQLite Encryption Extension (SEE) with Windows Phone 8

From Wiki
Jump to: navigation, search
vinayppatil (Talk | contribs)
m (Vinayppatil -)
hamishwillee (Talk | contribs)
m (Hamishwillee - Fix internal link in external format)
Line 178: Line 178:
  
  
{{SeeAlso|http://developer.nokia.com/community/wiki/Compiling_and_using_SQLite_with_Windows_Phone_8}}
+
{{SeeAlso|[[Compiling and using SQLite with Windows Phone 8]]}}

Revision as of 04:11, 4 February 2014

This article explains how to compile and use the SQLite Encryption Extension (SEE) with Windows Phone 8.

WP Metro Icon File.png
WP Metro Icon Tools.png
SignpostIcon XAML 40.png
WP Metro Icon WP8.png
Article Metadata
Tested with
SDK: Windows Phone 8.0 SDK
Compatibility
Platform(s):
Windows Phone 8
Article
Created: vinayppatil (15 Jan 2014)
Last edited: hamishwillee (04 Feb 2014)

Contents

Introduction

The SQLite Encryption Extension (SEE) is an add-on to the public domain version of SQLite that allows an app to transparently read and write encrypted database files.

Note.pngNote: While SQLite itself is public domain, SEE is commercially licensed software, available for a one-off cost of $2000USD.

There are general instructions on how to How To Compile And Use SEE.

This article provides information on how to build specifically for Windows Phone targets:

  1. Compile SEE for ARM and x86 targets (Simulator).
  2. Create an Extension SDK targeted to Windows Phone 8.
  3. Use SEE with your Windows Phone 8 applications.

Pre-requisites

Compiling SEE

Following below sections will allow you to compile SEE for ARM and x86 architectures.

Building binaries for ARM target

  1. Open Visual Studio 2012 ARM Phone Tools Command Prompt in administrator mode.
  2. Navigate to where you want to put the source or create a directory
    mkdir c:\sqlite-arm
    cd c:\sqlite-arm
  3. Get the latest SQLite source code
    fossil clone http://www.sqlite.org/cgi/src sqlite3.fossil
  4. Open the repository you just created
    fossil open sqlite3.fossil
  5. Type in the following commands in order
    SET NCRTLIBPATH=%ProgramFiles(x86)%\Microsoft Visual Studio 11.0\VC\WPSDK\WP80\lib
     
    SET NSDKLIBPATH=%ProgramFiles(x86)%\Windows Phone Kits\8.0\lib\x86
     
    SET USE_RC=0
     
    SET OPTS=-DWINAPI_FAMILY=WINAPI_FAMILY_PHONE_APP -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_WIN32_FILEMAPPING_API=1 -DSQLITE_HAS_CODEC=1
     
    nmake /F Makefile.msc sqlite3.c XCOMPILE=1 USE_NATIVE_LIBPATHS=1 FOR_WINRT=1 NO_TCL=1
     
    //Make sure you have copied see.c(SEE source code) in the folder
    COPY /B sqlite3.c + /B see.c sqlite3.c /B
     
    ATTRIB +r sqlite3.c
     
    ATTRIB +r sqlite3.h
     
    nmake -f Makefile.msc sqlite3.dll /I XCOMPILE=1 USE_NATIVE_LIBPATHS=1 FOR_WINRT=1 NO_TCL=1
    Final binaries

After this you should have sqlite3.dll, sqlite3.h, sqlite3.lib and sqlite3.pdb along with lot of other files generated in the source directory c:\sqlite-arm.

Build binaries for x86 target

  1. Open Visual Studio 2012 x86 Phone Tools Command Prompt in administrator mode.
  2. Create a source directory and navigate to it.
    mkdir c:\sqlite-x86
    cd c:\sqlite-x86
  3. Follow steps 3, 4 and 5 Building binaries for ARM target.
    Final binaries

After this you should have sqlite3.dll, sqlite3.h, sqlite3.lib and sqlite3.pdb along with lot of other files generated in the source directory c:\sqlite-x86.

Building the Extension SDK

Now that we have all the required binaries, let us create an Extension SDK targeted to Windows Phone 8.

  • Create a new project by File -> New -> Project -> Visual C# -> Extensibility -> VSIX project
  • Create a new file your_proj_name.props and place below source in it. (make sure to replace your_proj_name and version accordingly)
    <?xml version="1.0" encoding="utf-8"?>
    <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
    <PackageConfiguration Condition="'$(Configuration)' == ''">Debug</PackageConfiguration>
    <PackageConfiguration Condition="'$(Configuration)' == 'Debug'">Debug</PackageConfiguration>
    <PackageConfiguration Condition="'$(Configuration)' == 'Release'">Retail</PackageConfiguration>
    </PropertyGroup>
    <PropertyGroup>
    <IncludePath>$(FrameworkSDKRoot)\..\..\Windows Phone\v8.0\ExtensionSDKs\your_proj_name\version\DesignTime\CommonConfiguration\Neutral;$(IncludePath)</IncludePath>
    <LibraryPath>$(FrameworkSDKRoot)\..\..\Windows Phone\v8.0\ExtensionSDKs\your_proj_name\version\DesignTime\$(PackageConfiguration)\$(PlatformTarget);$(LibraryPath)</LibraryPath>
    <PropertySheetDisplayName> your_proj_name, version</PropertySheetDisplayName>
    </PropertyGroup>
    <ItemDefinitionGroup>
    <Link>
    <AdditionalDependencies>sqlite3.lib;%(AdditionalDependencies)</AdditionalDependencies>
    </Link>
    </ItemDefinitionGroup>
    </Project>
  • Create a new File SDKManifest.xml in the project root and place below contents in it (make sure to replace your_proj_name accordingly)
    <?xml version="1.0" encoding="utf-8" ?>
    <FileList
    DisplayName="SEE for Windows Phone"
    ProductFamilyName="your_proj_name"
    MoreInfo="http://www.sqlite.org/"
    MinVSVersion="11.0"
    SupportsMultipleVersions="Error"
    SupportedArchitectures="x86;ARM">
    </FileList>
  • Create hierarchy shown below in the app source and add respective files generated during build process to the project. Files from sqlite-x86 goes into x86 folders and files from sqlite-arm goes into ARM folders.
    Extension SDK hierarchy
  • Right click on one of the added files, click on Properties and change Build Action to Content, Copy to output directory to Copy always and Include in VSIX to True. Repeat this for all the added files.
  • Double click on source.extension.vsixmanifest.
  • Input following options on install targets tab.
    install targets tab options
  • Input below options in asset tab
    Assets tab options
  • Now build the project and .VSIX file should be generated in bin/{config} folder.

SEE Usage

  • Install SEE Extension SDK on your computer and restart Visual Studio.
  • Create a new Windows phone application.
  • Download sqlite-net-wp8 and add the Sqlite.vcxproj project to your solution (File -> Add -> Existing Project).
  • Add the required compilation symbols.
    • Right click on windows phone Project -> Properties
    • Click on the Build tab.
    • In the "Configuration" dropdown, select "All configurations".
    • In the "Platform" dropdown, select "All platforms".
    • Add "USE_WP8_NATIVE_SQLITE;WINDOWS_PHONE;SILVERLIGHT" to the "Conditional compilation symbols" textbox.
  • Add a reference of SEE extension to the SQLite project by:
    • Right click on SQLite Project -> Properties.
    • Click on Common properties tab.
    • Remove SQLite.WP80 from references.
    • Click on Add new reference
    • Windows phone -> Extensions -> SEE extension
  • Add sqlite-net nuget package to the windows phone project.
  • Add below lines to your constants.
    public static string KEY = "your_encryption_key_here";
     
    //This is your product activation key
    public static string ACTIVATION_CODE = "your_activation_code_here";
  • Add below statements right after creating the SQLiteConnection instance.
    //activates see with the activation code
    dbConn.Execute(String.Format("PRAGMA activate_extensions='see-{0}';", ACTIVATION_CODE));
     
    //sets encryption key on the newly created database
    dbConn.Execute(String.Format("PRAGMA key='{0}';", KEY));
  • After this use database as you usually do.


424 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×