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.

Encryption

Both classes support encryption, ensuring your data is stored securely.

We now offer enhanced encryption capabilities, including:

AES-GCM Encryption/Decryption: Support for the AES-GCM algorithm with random 96-bit initialization vectors and variable-length authentication tags, meeting the requirements for ePA-FdV certification by gematik and BSI. See the SBSDKAESGCMEncrypter class.

Advanced Key Derivation: New options for encryption key derivation, including PBKDF2, HKDF, and random key generation with variable key lengths (128 and 256 bits). These are available for both the standard AES encrypter (SBSDKAESEncrypter) and the new AES-GCM encrypter (SBSDKAESGCMEncrypter). See SBSDKStorageCryptingKeyGenerator, SBSDKRandomKeyGenerator, SBSDKPBKDF2KeyGenerator, and SBSDKHKDFKeyGenerator.

Protocol-Based Key Management: The new SBSDKStorageCryptingKeyProvider protocol enables flexible encryption key management. For example, the SBSDKVolatileKeyProvider class provides in-memory storage, restoration, and deletion of encryption keys. You can also implement custom key providers for persistent storage (e.g., keychain or file-based storage).

Context-Based Encryption: Added support for encryption/decryption on a per-context basis. Contexts, such as file URLs, are passed to encrypter APIs to enable context-based key derivation.

If the built-in encryption methods 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?