Skip to main content

Storage and encryption

Storage

By default, the native Scanbot Barcode Scanner SDKs as well as the Plugin itself use the internal and secure storage locations for all snapped barcode image files.

  • On Android all files will be stored in the internal files directory of your application. No permissions are required for your app to read or write files in this directory.

  • On iOS all files will be stored in the Application Support folder of your application.

Customize storage location

It is strongly recommended to use the default storage location. However, you can override the storage directory on initialization of the Plugin. The initializeSdk method can take an optional parameter storageBaseDirectory to set a custom storage location.

lib/doc_code_snippet/customize_storage_location.dart
loading...
lib/doc_code_snippet/customize_storage_location.dart
loading...

The value of storageBaseDirectory must be a file URL ('file:///...') that points to a valid platform-specific file system path. If this directory does not exist, the plugin will attempt to create it. To manage file system paths, we recommend using the Flutter plugin path_provider.

Warning

When overriding the default storage location, make sure

  • you have implemented a suitable storage permissions request handling
  • the storage directory is available (e.g. unmounted SD card).

👉 For more details about the storage locations on Android and iOS please also see:

Storage cleanup

There is no automatic file clean mechanism in this Plugin. Your app should decide when the perfect time is to remove the optional barcode image files snapped by this Plugin.

To avoid storage space issues caused by too many produced image files, it is strongly recommended implementing a suitable cleanup functionality based on the requirements of your app. This Plugin provides a cleanupBarcodeStorage method to remove all optional barcode image files snapped by this Plugin and thus keeps the storage clean.

Storage encryption

The Scanbot SDK provides the ability to store the generated image files (JPG, PNG), PDF, and TIFF files encrypted. This feature provides an additional level of security to the default secure storage locations of the native SDKs.

By default file encryption is disabled. To enable it you have to pass the following config parameters on SDK initialization:

  • password: A secure password or passphrase to derive the AES key for encryption/decryption.
  • mode: Encryption mode, AES128 or AES256 (default and recommended).
 var config = ScanbotSdkConfig(
encryptionParameters: EncryptionParameters(
password: "password",
mode: FileEncryptionMode.AES256,
),
);

await ScanbotBarcodeSdk.initScanbotSdk(config);

By activating the storage encryption the native Scanbot SDKs will use the built-in AES 128 or AES 256 encryption. All generated image files (JPG, PNG) including the preview image files, as well as the exported PDF files will be encrypted in memory and stored as encrypted data files on the device storage.

The Scanbot SDK derives the AES key from the given password, an internal salt value, and the internal number of iterations using the PBKDF2 function.

When applying image operations like cropping, rotation or image filters, the Scanbot SDK will decrypt the image files in memory, apply the changes, encrypt and store them again.

Also see Handle encrypted images.

Handle encrypted images

Display encrypted images

If the file encryption is enabled you will not be able to display preview images via file URIs (e.g. page.documentPreviewImageFileUri). Instead, you have to load the decrypted data of a preview image and use it for displaying an image. In order to do that there is the API function getDecryptedDataFromFile(Uri fileUri):

Page page = ...; // scanned page object

// Use the low-res image "documentPreviewImageFileUri" for the preview:
var decryptedImageData = await ScanbotEncryptionHandler.getDecryptedDataFromFile(
page.documentPreviewImageFileUri,
);

Image image = Image.memory(decryptedImageData); // Use image widget to show preview

👉 For a full implementation see our example app.

Upload encrypted images

To upload an image you have the following options:

1) Use the encrypted image file to upload to your server and decrypt it in the backend. Please contact our team to get support on how to generate the corresponding AES key and decrypt images on your backend.

2) Or alternatively, get the decrypted image data as Base64 on the mobile device by using the getDecryptedDataFromFile(Uri fileUri) function and use this data for the upload process:

Examples:

// For a Page image file:
Page page = ...; // scanned page object

// Use the final hi-res image "documentImageFileUri" for the upload process:
var decryptedImageData = await ScanbotEncryptionHandler.getDecryptedDataFromFile(
page.documentImageFileUri,
);
yourCustomUploadFunction(decryptedImageData);

// For a PDF or TIFF file generated by the Scanbot SDK:
Uri fileUri = ...; // Uri of the generated PDF or TIFF file

var decryptedFileData = await ScanbotEncryptionHandler.getDecryptedDataFromFile(fileUri);
yourCustomUploadFunction(decryptedFileData);

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?