Skip to content

Skyost/SimpleSecureStorage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

106 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Secure Storage

A simple and secure storage system for Flutter. Supports Android, iOS, macOS, Windows and web !

Pub Likes Pub Points Maintained with Melos

Motivations

I'm currently creating a TOTP app in which secrets are encrypted with a master password, and I need a secure place to store the encryption/decryption key.

That's why I decided to create my own solution : Simple Secure Storage (SSS).

Features

  • Very very simple and straightforward.
  • Supports Android, iOS, macOS, Windows, Linux, and the web.
  • Supports caching data for faster access.
  • Secure.
  • Again, very simple.

Getting started

Minimum requirements

Simple Secure Storage uses :

Installation

Run the following command to add Simple Secure Storage to your Flutter project :

flutter pub add simple_secure_storage

Then follow the instructions for each platform you target.

Android

As stated on Android Developers,

Warning

The preference file should not be backed up with Auto Backup. When restoring the file it is likely the key used to encrypt it will no longer be present. You should exclude all EncryptedSharedPreferences from backup using backup rules.

Either disable Auto Backup entirely in your AndroidManifest.xml :

<application
     <!-- Some settings -->
    android:allowBackup="false"
    android:fullBackupContent="false">

or exclude only the encrypted shared preferences using backup rules. The sharedpref path is the namespace value passed to the plugin's initialize method.

macOS

In Xcode, go to Project settings > Capabilities and enable Keychain Sharing (see this).

Linux

These requirements are typically already satisfied by default on most desktop environments.

  • D-Bus support.
  • A running Secret Service implementation (such as GNOME Keyring, KDE Wallet, or another implementation providing the org.freedesktop.secrets D-Bus service).

Tip

Starting from 0.3.0, installing GNOME libsecret is no longer required. The Linux implementation uses the Secret Service D-Bus API directly.

Code snippet

Here's a simple example to get started.

// Initialize the plugin before using it, typically in your `main()` method.
// You can provide a namespace and application name through `InitializationOptions`.
if (kIsWeb) {
  // To secure your data on Flutter web, we have to encrypt it using a password and a salt.
  await SimpleSecureStorage.initialize(WebInitializationOptions(keyPassword: 'password', encryptionSalt: 'salt'));
} else {
  await SimpleSecureStorage.initialize(); // You can also pass `InitializationOptions` here.
}

// Write a value.
await SimpleSecureStorage.write('key', 'value');

// Check if a value exists.
print(await SimpleSecureStorage.has('key')); // Will print "true".

// Read a value.
print(await SimpleSecureStorage.read('key')); // Will print "value".

// Remove a value.
await SimpleSecureStorage.delete('key');

// Clear everything.
await SimpleSecureStorage.clear();

In the previous snippet, everything is being read "on demand". You may want to access your data without always having to write await. To do so, use the class CachedSimpleSecureStorage. It behaves exactly like the snippet above, except you call await CachedSimpleSecureStorage.getInstance() instead of await SimpleSecureStorage.initialize().

If you want a more complete example, feel free to check and run this one, which is available on GitHub. To run the example app on Apple platforms (iOS and macOS), configure the development team in the project settings.

Contributions

There are several ways to contribute to this project :

About

A simple and secure storage system for Flutter.

Topics

Resources

License

Contributing

Stars

4 stars

Watchers

1 watching

Forks

Contributors