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.
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:
- Swift
- Objective-C
// 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)
// Create a Url pointing to the directory where you plan to store the images
NSURL *imagesDirectoryURL = [[SBSDKStorageLocation applicationDocumentsFolderURL]
URLByAppendingPathComponent:@"Images"];
// Create a storage location using the Url pointing to the images directory
SBSDKStorageLocation *storageLocation = [[SBSDKStorageLocation alloc] initWithBaseURL:imagesDirectoryURL];
// Create encrypter with a password and the desired encryption mode
SBSDKAESEncrypter *encrypter = [[SBSDKAESEncrypter alloc] initWithPassword:@"password_example#42"
mode:SBSDKAESEncrypterModeAES256];
// Create an indexed image storage using the storage location, image file format and encrypter
SBSDKIndexedImageStorage *imageStorage = [[SBSDKIndexedImageStorage alloc] initWithStorageLocation:storageLocation
fileFormat:SBSDKImageFileFormatJPEG
encrypter:encrypter];
Examples of some basic operations on Indexed Image storage:
- Swift
- Objective-C
// 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)
// In the example we are using temporary image storage
SBSDKIndexedImageStorage *imageStorage = [SBSDKIndexedImageStorage temporary];
// Create an image
UIImage *image = [UIImage imageNamed:@"testImage"];
// Create an index
NSInteger index = 0;
// Get the image at index
UIImage *storedImage = [imageStorage imageAtIndex:index];
// Add an image to storage
BOOL isAdded = [imageStorage addImage:image];
// Insert an image at index
BOOL isInserted = [imageStorage insertImage:image atIndex:index];
// Remove the image at index
[imageStorage removeImageAtIndex:index];
// Move an image from index to index
// Create a new index to move the image to
NSInteger newIndex = 1;
BOOL isMoved = [imageStorage moveImageFromIndex:index toIndex:newIndex];
// Replace an image at index with another image
// Create an image to replace a stored one
UIImage *newImage = [UIImage imageNamed:@"newTestImage"];
BOOL isReplaced = [imageStorage replaceImageAtIndex:index withImage:newImage];
Examples of some basic operations on Keyed Image storage:
- Swift
- Objective-C
// 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)
// Create an image storage using storage location, in the example we are using a temporary location
SBSDKKeyedImageStorage *imageStorage = [[SBSDKKeyedImageStorage alloc] initWithStorageLocation:[SBSDKStorageLocation temporary]];
// Create an image
UIImage *image = [UIImage imageNamed:@"testImage"];
// Create a key
NSString *key = @"testKey";
// Set an image for key
[imageStorage setImage:image forKey:key];
// Get the image for key
UIImage *storedImage = [imageStorage imageForKey:key];
// Remove the image for key
[imageStorage removeImageForKey:key];
// Remove images for keys matching prefix
// Create a prefix
NSString *prefix = @"test";
[imageStorage removeImagesForKeysMatchingPrefix:prefix];
Want to scan longer than one minute?
Generate a free trial license to test the Scanbot SDK thoroughly.
Get your free Trial LicenseWhat do you think of this documentation?
What can we do to improve it? Please be as detailed as you like.