Secure Storage with BlackBerry Dynamics

So, you want to use BlackBerry Dynamics secure storage in place of Apple’s default storage. Where do you start? I am going to expect you are already familiar with Apple’s storage options (CoreData and SQLite).

Using BlackBerry Dynamics APIs for CoreData and SQLite means the data is encrypted by the Dynamics SDK at rest.

Here is my recipe for doing things the BlackBerry Dynamics way:

  • You need to include BlackBerry Dynamics in your application. You can download the SDK from here.
  • Then replace the following native APIs with similarly named BlackBerry Dynamics APIs for storage.
Apple’s native API BlackBerry Dynamics API
NSPersistentStoreCoordinator GDPersistentStoreCoordinator
NSSQLiteStoreType, NSXMLStoreType,
NSBinaryStoreType, NSInMemoryStoreType
sqlite3_open sqlite3enc_open
  • Build and Run…

How to use SQL with BlackBerry Dynamics

You need to create the database by using the File Manager API from BlackBerry Dynamics. You will need to import SQLite from the BlackBerry Dynamics library which can be done by importing GD_C.SecureStore.SQLite. All the other functions should be the same as they are in the original SQLite library.

if sqlite3enc_open(fileURL.path, &sqlite3Database) != SQLITE_OK {

            print("error opening database")


How to use CoreData with BlackBerry Dynamics

If you are creating a new app then you can check the “Use Core Data” checkmark and everything will be preconfigured with the BlackBerry Dynamics app.

If you are using a pre-existing application. Here are the steps

  • Add CoreData Data Model to the project.
  • Copy the code of this file (Swift, Objective-C) marked Core Data Stack in your Application Delegate.
  • Update the name of the Data Model.
let coordinator = GDPersistentStoreCoordinator(managedObjectModel: self.managedObjectModel)

        let url = self.applicationDocumentsDirectory.appendingPathComponent("SingleViewCoreData.sqlite")

        var failureReason = "There was an error creating or loading the application's saved data."

        do {

            try coordinator.addPersistentStore(ofType: GDEncryptedIncrementalStoreType, configurationName: nil, at: url, options: nil)

        } catch {

            // Report any error we got.


After replacing your code with BlackBerry Dynamics APIs you should find the behavior is the same. Here is a link to my Swift sample and Objective C sample on GitHub. These samples have all the APIs implemented.

Happy Coding!!

Gurjit Ghangura

About Gurjit Ghangura

Enterprise Solutions Developer, Love BlackBerry, Developer at Heart.