Skip to Content

Getting Started with Kapsel – Part 5 — EncryptedStorage



The EncryptedStorage plugin provides an asynchronous API to store key value pairs securely.  The API is based on the the web storage interface but is asynchronous in nature.

For additional details see the JavaScript file in a project that includes this plugin at


or the JS Documentation at Kapsel EncryptedStorage API Reference.

The following steps will demonstrate this plugin.

  • Create the project.
    cordova -d create C:\Kapsel_Projects\StorageDemo StorageDemo "{\"plugin_search_path\":\"C:/SAP/MobileSDK3/KapselSDK/plugins/\"}"
    cd StorageDemo
    cordova -d platform add android
    cordova -d create ~/Documents/Kapsel_Projects/StorageDemo StorageDemo "{\"plugin_search_path\":\"/Users/i826567/SAP/MobileSDK3/KapselSDK/plugins/\"}"
    cd ~/Documents/Kapsel_Projects/StorageDemo
    cordova -d platform add ios
  • Add the enycryptedstorage plugin.
    cordova -d plugin add
  • Replace www\index.html with index.htmland run
    cordova -d prepare

    Notice that the API is asynchronous.  This can make it a bit more challenging to work with.  The article Asynchronous JS: Callbacks, Listeners, Control Flow Libs and Promise provides some suggestions on how to work with asynchronous methods.

  • Use the Android IDE or Xcode to deploy and run the project. 
  • If the Logging plugin is added and the log level set to debug, the messages logged by the EncryptedStorage plugin can be viewed.  The log tag it uses is SMP_ENCRYPTED_STORAGE.
  • Note that as of SP03, the data vault of the Logon plugin is required by the EncryptedStorage plugin.  The Logon plugin can be initialized using a new method in SP03 called sap.Logon.initPasscodeManager.  This is to be used instead of sap.Logon.init if the application is not registering against an SAP Mobile Platform or Gateway server and Logon plugin’s data vault is required.

    In SP03 the encryption keys are stored in the Logon Plugin’s data vault and the constructor

    new sap.EncryptedStorage(store_name)

    no longer takes a password as a parameter.  The data contained in a store created with versions prior to SP03 is not migrated to SP03.

    Note that as of SMP 3.0 SP02, if the Logon plugin’s data vault is deleted, the EncyptedStorage plugin will also delete all storage as well.  This can occur when the user clicks the Forgot Application Passcode button on the unlock screen of the Logon plugin, if the user enters too many incorrect passcodes or if the method  sap.Logon.core.deleteRegistration is called.

    Note on Android, not more than 1 MB can be stored for a single key/value pair prior to SP03.

  • The following are some technical details of where the data is stored on Android.
    Key value pairs are stored in a SQLLite Database.
    The database is created using local storage which can only be accessed by the application that created it.  The file is stored under /data/data/packageName and can be seen and accessed when using an emulator but not a device.

    As of SP03 the values and the keys stored in this SQLLite database are encrypted.  See EncryptedStorage Plugin for additional technical details on the encryption used to store the data.

Back to Getting Started With Kapsel

You must be Logged on to comment or reply to a post.
    • Hi, When I am trying getItem method offline, I am getting the following error.

      EncryptionHelper$DataEncryptionException: Datavault not accessable.

      Kindly help me in fixing it up.


      Balajee B

      • What OS version are you trying this on?  Did you make any additional changes to the provided index.html?  Do you have any additional instructions on how to reproduce the problem?  Are you using the SP03 Kapsel plugins with Cordova 3.4.0-0.1.3?

  • I tried this on android but I found some problems, first off the application showed an error that sap.Logon.initPasscodeManager is undefined (uncaught Type error: Object#<Object> has no method 'initPasscodeManager ') while I added the logon plugin in the project. I pressed OK on the error shown and found that all function were working perfectly except for Delete Storage function (uncaught TypeError: Object[object Object] has no method 'deleteStore'). I tried also to use sap.Logon.init everything was working except the Delete Storage. How did everything worked without sap.initPasscodeManager? and why the deleteStorage function is not working? I also tried to remove all logon function and everything worked.How this happened while it is mentioned that Logon plugin is required by EncryptedStorage to store the encryption keys  the Logon Plugin's data vault, isn't this weird? by the way I'm using SMP 3.0

  • Hi Daniel,

    I am getting Null reference exception while calling any method of EncryptedStorage. I am developing for Windows 8.1. I am using SMP SDK 3.0 SP07.

    Error: Invalid pointer System.NullReferenceException: Object reference not set to an instance of an object.


    Nikhil Agarwala

    • I have forwarded this question on to one of my colleagues who works with Windows development.

      I just gave the sample a quick try on Android and did not encounter a problem.


      Dan van Leeuwen

        • Yesterday was a public holiday in Canada. 

          One other thing to try would to try it again using the just released SP08 PL01 SDK.

          Were there any errors when creating the project or adding the plugins?


          Dan van Leeuwen

          • Hi Nikhil,

            how do you use the UltraLite library (needed for EncryptedStorage lib)?

            I could reproduce the NullReferenceException with only using UltraLite.winmd which is only a wrapper above dll (I called setItem method from JS). Adding UltraLite.dll to the sample's build folder fixed the error.

            Best regards,


  • Nikhil,

    1) Did you create the store before calling any other method?

    2) I used 3.8 build and could not reproduce this issue.

    Are you using the index.html that is included on this page? If not, please share your index.html.


  • Thanks for the informative article. I have the plugin working, my only question is can you store data types other than string values?  I need to be able to store arrays that include all data types.  How would this be accomplished?  Thank you!

  • Hi,

    I am able to successfully test the sample application. But for my application I am registering to SMP using HTTPS POST method with no passcode screen. How can use the EncryptedStorage plugin?

    I am using SP08. The error that I am getting for setItem method is:

    The text associated with this error code could not be found.

    SAP.Logon.LogonCore+LogonException: Exception of type 'SAP.Logon.LogonCore+LogonException' was thrown.

    at SAP.EncryptedStorage.StorageDb.<setItem>d__0.MoveNext()

    --- End of stack trace from previous location where exception was thrown ---

    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

    at SAP.EncryptedStorage.StorageDbAsync.<>c__DisplayClass1.<<setItem>b__0>d__3.Mov



    • I don't believe the encrypted storage plugin lets you plugin another database, but I don't see any reason you could not use another solution such as pouchdb instead of the encrypted storage plugin from the SDK.

  • What is the data size limit of SAP Encrypted Storage in iOS and Android in Megabytes (MB)?

    Also, what is the size limit for Individual Key value pair in iOS and Android in megabytes (MB) in latest SMP SDK SP 14?