Latest 1.0.0
License MIT
Platforms ios 8.0, requires ARC

A lightweight library that lets you store any swift type with AES 256 encryption. Encryption keys are generated at runtime and stored in device keychain.


SecureStorage can be installed via CocoaPods:

target 'ProjectName' do
    pod 'SecureStorage'


SecureStorage allows you to store you swift type in UserDefaults, shared defaults or on disk. Shared defaults allow you to share data among applications. Encryption keys can also be stored in shared keychain to enable sharing keys among applications.


SecureStorage initialization has three parts:

Storage Location

You can choose storage location during initialization. Available values are:

  • UserDefaults: This is the default storage location. It is used when no storage location is provided.

    let secureStorage = SecureStorage(keychainAccessGroup: nil)
  • File location: If a folder path is provided during initialization, encrypted data will be stored as files in that folder. Keys will be used as file names. Throws initialization failed error if a file already exists at provided location or if the location is not a directory.

    let secureStorage = try! SecureStorage(fileLocation: fileLocation, keychainAccessGroup: nil)
  • Shared defaults: SecureStorage also allows you to store encrypted data in shared defaults to enable sharing encrypted data among applications. You need to enable App Groups in your application’s capabilities and provide the app group identifier to SecureStorage during initialization. Throws initialization failed error if shared defaults could not be initialized.

    let secureStorage = try! SecureStorage(sharedDefaultsId: "", keychainAccessGroup: nil)

Keychain Group

You can choose to store encryption keys in shared keychain to enable sharing of keys among applications. This can be used in conjuntion with shared defaults to share encrypted objects among applications. To use this option, you need to enable Keychain sharing in your application capabilities and provide Keychain group identifier during SecureStorage initialization.

// Below initialization stores data in shared defalults
// and encryption keys are stored in shared keychain
let secureStorage = try! SecureStorage(sharedDefaultsId: "", keychainAccessGroup: "your.keychain.sharing.identifier")

Keychain Access Control

SecureStorage also allows applications to set keychain access level policy. Default value is set to strictest policy kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly. If you need to choose a different policy you can choose that during initialization.

let secureStorage = SecureStorage(keychainAccessGroup: nil, keychainAccessControl: kSecAttrAccessibleAlways)

Accessing Objects

Post initialization, storing and retrieving swift types from SecureStorage is very simple.

// Initialize SecureStorage
let secureStorage = SecureStorage(keychainAccessGroup: nil)
// Store data
try, for: keyForStorage)
// retrieve data
let text = try secureStorage.fetchObject(for: keyForStorage)
// delete data
secureStorage.removeObject(for: keyForStorage)


SecureStorage is released under MIT License.

Latest podspec

    "name": "SecureStorage",
    "version": "1.0.0",
    "summary": "A simple utility to store objects securely on disk or in defaults",
    "description": "A simple library that allows applications to store Objective-C/Swift objects securely on disk or in user defaults.",
    "homepage": "",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "authors": {
        "Adarsh Rai": "[email protected]"
    "platforms": {
        "ios": "8.0"
    "source": {
        "git": "",
        "tag": "1.0.0"
    "source_files": "SecureStorage/**/*.{h,m,swift}",
    "requires_arc": true,
    "preserve_paths": [
    "swift_version": "4.1",
    "pod_target_xcconfig": {
        "SWIFT_INCLUDE_PATHS[sdk=iphoneos*]": "$(PODS_ROOT)/SecureStorage/SecureStorage/modulemaps/iphoneos",
        "SWIFT_INCLUDE_PATHS[sdk=iphonesimulator*]": "$(PODS_ROOT)/SecureStorage/SecureStorage/modulemaps/iphonesimulator",
        "SWIFT_VERSION": "4.1"

Pin It on Pinterest

Share This