flutter_string_encryption 0.0.1

  • README.md
  • Example
  • Installing
  • Versions
  • 80


Cross-platform string encryption using common best-practices (AES/CBC/PKCS5/Random IVs/HMAC-SHA256 Integrity Check).

It uses the format described in this article.

It currently uses Native Platform implementations, which are (we all hope) constantly vetted and updated by Apple and Google, with some really tiny library wrappers to ease some of the tedious work.

For the Android side, I used the following library (coming from the same authors of the article above): https://github.com/tozny/java-aes-crypto

For the iOS side, I implemented the format described in the article directly inside the native plugin, and used the following library to help me with Apple's CommonCrypto functions which are not really easy to interact with otherwise: https://github.com/sgl0v/SCrypto


In order to work on iOS, you need to bump the iOS support version up to 9.0. This can be done inside your ios project Podfile by uncommenting the very first line of the file:

# Uncomment this line to define a global platform for your project
platform :ios, '9.0'


final PlatformStringCryptor cryptor = new PlatformStringCryptor();

Generate A Secret Key


Generate it and store it in a safe place - e.g. the Keychain/KeyStore

final String key = cryptor.generateRandomKey();


Generate and (safely) store the salt, and then generate the key with a user-provided password before encrypting/decrypting your strings.

final String password = "user_provided_password";
final String salt = cryptor.generateSalt();
final String key = crypto.generateKeyFromPassword(password, salt);

Encrypt A String

final String encrypted = cryptor.encrypt("A string to encrypt.", key);

Decrypt A String

try {
  final String decrypted = cryptor.decrypt(encrypted, key);
  print(decrypted); // - A string to encrypt.
} on MacMismatchException {
  // unable to decrypt (wrong key or forged data)


MIT (both this plugin and the used helper libraries).

[0.0.1] - Initial Release


import 'package:flutter/material.dart';
import 'package:flutter_string_encryption/flutter_string_encryption.dart';

void main() => runApp(new MyApp());

class MyApp extends StatefulWidget {
  _MyAppState createState() => new _MyAppState();

class _MyAppState extends State<MyApp> {
  String _randomKey = 'Unknown';
  String _string = "Unknown";
  String _encrypted = "Unknown";

  initState() {

  // Platform messages are asynchronous, so we initialize in an async method.
  initPlatformState() async {
    final cryptor = new PlatformStringCryptor();

    final key = await cryptor.generateRandomKey();
    print("randomKey: $key");

    final string = "here is the string, here is the string.";
    final encrypted = await cryptor.encrypt(string, key);
    final decrypted = await cryptor.decrypt(encrypted, key);

    assert(decrypted == string);

    final wrongKey =

    try {
      await cryptor.decrypt(encrypted, wrongKey);
    } on MacMismatchException {
      print("wrongly decrypted");

    final salt = "Ee/aHwc6EfEactQ00sm/0A=="; // await cryptor.generateSalt();
    final password = "a_strong_password%./😋";
    final generatedKey = await cryptor.generateKeyFromPassword(password, salt);
    print("salt: $salt, key: $generatedKey");

    assert(generatedKey == wrongKey);

    setState(() {
      _randomKey = key;
      _string = string;
      _encrypted = encrypted;

  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: new Text('Plugin example app'),
        body: new Center(
          child: new Text(
              'Random key: $_randomKey\n\nString: $_string\n\nEncrypted: $_encrypted'),

1. Depend on it

Add this to your package's pubspec.yaml file:

  flutter_string_encryption: "^0.0.1"

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter packages get

Alternatively, your editor might support packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:flutter_string_encryption/flutter_string_encryption.dart';
Version Uploaded Documentation Archive
0.0.1 Jan 8, 2018 Go to the documentation of flutter_string_encryption 0.0.1 Download flutter_string_encryption 0.0.1 archive


This feature is new.
We welcome feedback.
More details: scoring.

We analyzed this package, and provided a score, details, and suggestions below.

  • completed on Feb 3, 2018
  • Dart: 2.0.0-dev.20.0
  • pana: 0.10.1
  • Flutter: 0.0.22


Describes how popular the package is relative to other packages. [more]
59 / 100
Code health derived from static analysis. [more]
100 / 100
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]


Detected platforms: Flutter

References Flutter, and has no conflicting libraries.


  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.


Package Constraint Resolved Available
Direct dependencies
flutter 0.0.0
Transitive dependencies
async 2.0.3
charcode 1.1.1
collection 1.14.5
http 0.11.3+16
http_parser 3.1.1
meta 1.1.1 1.1.2
path 1.5.1
sky_engine 0.0.99
source_span 1.4.0
string_scanner 1.0.2
typed_data 1.1.4 1.1.5
vector_math 2.0.5