Giter Club home page Giter Club logo

flutter_string_encryption's Introduction

flutter_string_encryption

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

Support

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'

Usage

final cryptor = new PlatformStringCryptor();

Generate A Secret Key

Randomly

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

final String key = await cryptor.generateRandomKey();

Password-Based

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

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

Encrypt A String

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

Decrypt A String

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

License

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.