Skip to main content

Storage and Encryption | iOS Document Scanner

The Scanbot SDK comes with built-in image storage. You can store scanned images using either keyed or indexed storage. We provide convenient interfaces for this via the SBSDKKeyedImageStorage and SBSDKIndexedImageStorage classes.

SBSDKKeyedImageStorage is a simple thread-safe multiple-reader-single-writer key-value fashioned disk image cache class. This class manages images in a dictionary-like fashion.

SBSDKIndexedImageStorage is a simple thread-safe multiple-reader-single-writer index-based disk image cache class. This class manages images in an array-like fashion.

Both classes support JPEG (recommended) and PNG image file formats represented in SBSDKImageFileFormat Enumeration.

Both classes support encryption, so your data is stored securely. We provide built-in support for AES128 and AES256 encryption. If these algorithms do not meet your requirements you can create your own encrypter by implementing a class conforming to the SBSDKStorageCrypting protocol.

Please note

Encryption is not enabled by default.

For easier access to the device's file system, the Scanbot SDK provides a convenient helper class SBSDKStorageLocation.

Example of creating indexed image storage using SBSDKStorageLocation and built-in AES256 encrypter:

// Create a Url to the directory where you plan to store the images
let imagesDirectoryURL = SBSDKStorageLocation.applicationDocumentsFolderURL.appendingPathComponent("Images")

// Create a storage location using the Url pointing to the images directory
let storageLocation = SBSDKStorageLocation.init(baseURL: imagesDirectoryURL)

// Create encrypter with a password and the desired encryption mode
let encrypter = SBSDKAESEncrypter(password: "password_example#42", mode: .AES256)

// Create an indexed image storage using the storage location, image file format and encrypter
let imageStorage = SBSDKIndexedImageStorage(storageLocation: storageLocation,
fileFormat: .JPEG,
encrypter: encrypter)

Examples of some basic operations on Indexed Image storage:

// In the example we are using temporary image storage
guard let imageStorage = SBSDKIndexedImageStorage.temporary else { return }

// Create an image
guard let image = UIImage(named: "testImage") else { return }

// Create an index
let index: Int = 0

// Get the image at index
let storedImage = imageStorage.image(at: index)

// Add an image to storage
let isAdded = imageStorage.add(image)

// Insert an image at index
let isInserted = imageStorage.insert(image, at: index)

// Remove the image at index
imageStorage.removeImage(at: index)

// Move an image from index to index
// Create a new index to move the image to
let newIndex: Int = 1
let isMoved = imageStorage.moveImage(from: index, to: newIndex)

// Replace an image at index with another image
// Create an image to replace a stored one
guard let newImage = UIImage(named: "newTestImage") else { return }
let isReplaced = imageStorage.replaceImage(at: index, with: newImage)

Examples of some basic operations on Keyed Image storage:

// Create an image storage using storage location, in the example we are using a temporary location
let imageStorage = SBSDKKeyedImageStorage()

// Create an image
guard let image = UIImage(named: "testImage") else { return }

// Create a key
let key = "testKey"

// Set an image for key
imageStorage?.set(image: image, for: key)

// Get the image for key
let storedImage = imageStorage?.image(for: key)

// Remove the image for key
imageStorage?.removeImage(for: key)

// Remove images for keys matching a prefix
// Create a prefix
let prefix = "test"
imageStorage?.removeImages(matchingPrefix: prefix)

Want to scan longer than one minute?

Generate a free trial license to test the Scanbot SDK thoroughly.

Get your free Trial License

What do you think of this documentation?