Skip to main content

Storing and encrypting data with the React Native Barcode Scanner SDK

The Scanbot SDK uses the internal and secure storage locations for the images by default.

  • 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.

Customizing the storage location

We strongly recommended using the default storage location. However, you can override the storage directory when initializing the SDK.

The initializeSdk method can take an optional parameter storageBaseDirectory to set a custom storage location.

Scanbot Barcode Scanner SDK Initialization With Custom Storage
loading...

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 SDK will try to create it.

To work with the file system, we recommend the npm module react-native-fs.

For the full demo code, please refer to our example app scanbot-barcode-scanner-sdk-example-react-native.

warning

When overriding the default storage location, make sure

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

👉 For more details about the storage locations on Android and iOS, please refer to:

Storage cleanup

The Scanbot SDK does not have an automatic file clean mechanism, since only your app can decide when the perfect time is to remove the image files produced by the SDK.

To avoid storage space issues caused by too many produced image files, we strongly recommend implementing a suitable cleanup functionality based on the requirements of your app.

The SDK provides the following helper method to keep the storage clean.

await ScanbotBarcodeSDK.cleanup();

Storage encryption

The Scanbot SDK provides the ability to store the generated image files (JPG, PNG) 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, pass the following config parameters on SDK initialization:

  • fileEncryptionPassword: A secure password or passphrase to derive the AES key for encryption/decryption.
  • fileEncryptionMode: The encryption mode, either AES128 or AES256 (default and recommended).
Scanbot Barcode Scanner SDK Initialization With Encryption
loading...

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

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.

Handling encrypted images

If file encryption is enabled, you will not be able to display preview images via file URIs. Instead, you have to load the decrypted data of a preview image and use it for displaying an image.

To do this, use the API function getImageData(imageFileUri: string):

const result = await ScanbotBarcodeSDK.getImageData(imageFileUri);
const decryptedImageDataAsBase64 = `data:image/jpeg;base64,${result}`;
...
<Image source={uri: decryptedImageDataAsBase64} style={...} />

Want to scan longer than one minute?

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

Get free trial license