Skip to main content

Storage and Encryption | Flutter Barcode Scanner


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.

Directory storageDirectory;
if (Platform.isAndroid) {
storageDirectory = await getExternalStorageDirectory();
if (Platform.isIOS) {
storageDirectory = await getApplicationDocumentsDirectory();

// Please note: getExternalStorageDirectory() and getApplicationDocumentsDirectory()
// are provided via 3rd-party plugins like "path_provider".

var config = ScanbotSdkConfig(
storageBaseDirectory: "${directory.path}/my_custom_storage",
await ScanbotBarcodeSdk.initScanbotSdk(config);

The value of the storageBaseDirectory must be a file URL ('file:///...) pointing to a valid platform-specific file system path. If this directory does not exist yet, the Plugin will try to create it. To work with the file system we recommend the Flutter Plugin path_provider.

⚠️ Note: When overriding the default storage location, make sure

  • you have implemented a suitable storage permissions request handling on Android
  • you fully understand the consequences regarding the accessibility (security) of the produced document files

👉 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(imageFileUri: string):

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(imageFileUri: Uri) function and use this data for the upload process:


// 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);

// 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);

Want to scan longer than one minute?

Generate your free "no-strings-attached" Trial License and properly test the Scanbot SDK.

Get your free Trial License

What do you think of this documentation?