Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .dart_tool/package_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"configVersion": 2,
"packages": [
{
"name": "characters",
"rootUri": "file:///Users/francis/bin/flutter/.pub-cache/hosted/pub.dartlang.org/characters-1.1.0",
"packageUri": "lib/",
"languageVersion": "2.12"
},
{
"name": "collection",
"rootUri": "file:///Users/francis/bin/flutter/.pub-cache/hosted/pub.dartlang.org/collection-1.15.0",
"packageUri": "lib/",
"languageVersion": "2.12"
},
{
"name": "flutter",
"rootUri": "file:///Users/francis/bin/flutter/packages/flutter",
"packageUri": "lib/",
"languageVersion": "2.12"
},
{
"name": "meta",
"rootUri": "file:///Users/francis/bin/flutter/.pub-cache/hosted/pub.dartlang.org/meta-1.3.0",
"packageUri": "lib/",
"languageVersion": "2.12"
},
{
"name": "sky_engine",
"rootUri": "file:///Users/francis/bin/flutter/bin/cache/pkg/sky_engine",
"packageUri": "lib/",
"languageVersion": "2.12"
},
{
"name": "typed_data",
"rootUri": "file:///Users/francis/bin/flutter/.pub-cache/hosted/pub.dartlang.org/typed_data-1.3.0",
"packageUri": "lib/",
"languageVersion": "2.12"
},
{
"name": "vector_math",
"rootUri": "file:///Users/francis/bin/flutter/.pub-cache/hosted/pub.dartlang.org/vector_math-2.1.0",
"packageUri": "lib/",
"languageVersion": "2.12"
},
{
"name": "flutter_string_encryption",
"rootUri": "../",
"packageUri": "lib/",
"languageVersion": "2.12"
}
],
"generated": "2021-04-22T13:22:10.694041Z",
"generator": "pub",
"generatorVersion": "2.13.0-211.6.beta"
}
33 changes: 33 additions & 0 deletions .dart_tool/package_config_subset
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
characters
2.12
file:///Users/francis/bin/flutter/.pub-cache/hosted/pub.dartlang.org/characters-1.1.0/
file:///Users/francis/bin/flutter/.pub-cache/hosted/pub.dartlang.org/characters-1.1.0/lib/
collection
2.12
file:///Users/francis/bin/flutter/.pub-cache/hosted/pub.dartlang.org/collection-1.15.0/
file:///Users/francis/bin/flutter/.pub-cache/hosted/pub.dartlang.org/collection-1.15.0/lib/
meta
2.12
file:///Users/francis/bin/flutter/.pub-cache/hosted/pub.dartlang.org/meta-1.3.0/
file:///Users/francis/bin/flutter/.pub-cache/hosted/pub.dartlang.org/meta-1.3.0/lib/
typed_data
2.12
file:///Users/francis/bin/flutter/.pub-cache/hosted/pub.dartlang.org/typed_data-1.3.0/
file:///Users/francis/bin/flutter/.pub-cache/hosted/pub.dartlang.org/typed_data-1.3.0/lib/
vector_math
2.12
file:///Users/francis/bin/flutter/.pub-cache/hosted/pub.dartlang.org/vector_math-2.1.0/
file:///Users/francis/bin/flutter/.pub-cache/hosted/pub.dartlang.org/vector_math-2.1.0/lib/
sky_engine
2.12
file:///Users/francis/bin/flutter/bin/cache/pkg/sky_engine/
file:///Users/francis/bin/flutter/bin/cache/pkg/sky_engine/lib/
flutter
2.12
file:///Users/francis/bin/flutter/packages/flutter/
file:///Users/francis/bin/flutter/packages/flutter/lib/
flutter_string_encryption
2.12
file:///Users/francis/projects/flutter_string_encryption/
file:///Users/francis/projects/flutter_string_encryption/lib/
2
1 change: 1 addition & 0 deletions .dart_tool/version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.2.0-10.1.pre
1 change: 1 addition & 0 deletions example/.flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_string_encryption","path":"/Users/francis/projects/flutter_string_encryption/","dependencies":[]}],"android":[{"name":"flutter_string_encryption","path":"/Users/francis/projects/flutter_string_encryption/","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"flutter_string_encryption","dependencies":[]}],"date_created":"2021-04-22 14:22:12.946538","version":"2.2.0-10.1.pre"}
1 change: 1 addition & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ ios/.generated/
packages
pubspec.lock
.flutter-plugins
.dart_tool/
14 changes: 14 additions & 0 deletions example/ios/Flutter/flutter_export_environment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=/Users/francis/bin/flutter"
export "FLUTTER_APPLICATION_PATH=/Users/francis/projects/flutter_string_encryption/example"
export "COCOAPODS_PARALLEL_CODE_SIGN=true"
export "FLUTTER_TARGET=lib/main.dart"
export "FLUTTER_BUILD_DIR=build"
export "SYMROOT=${SOURCE_ROOT}/../build/ios"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1"
export "DART_OBFUSCATION=false"
export "TRACK_WIDGET_CREATION=false"
export "TREE_SHAKE_ICONS=false"
export "PACKAGE_CONFIG=.packages"
4 changes: 2 additions & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ class MyApp extends StatefulWidget {
}

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

@override
initState() {
Expand Down
3 changes: 3 additions & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ dev_dependencies:
flutter_string_encryption:
path: ../

environment:
sdk: '>=2.12.0 <3.0.0'

# For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/tools/pub/pubspec

Expand Down
20 changes: 10 additions & 10 deletions lib/flutter_string_encryption.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,34 @@ import 'package:flutter/services.dart';
/// Interface for the Plugin
abstract class StringCryptor {
/// Generates a random key to use with [encrypt] and [decrypt] methods
Future<String> generateRandomKey();
Future<String?> generateRandomKey();

/// Gets a key from the given [password] and [salt]. [salt] can be generated
/// with [generateSalt] while [password] is usually provided by the user.
Future<String> generateKeyFromPassword(String password, String salt);
Future<String?> generateKeyFromPassword(String password, String salt);

/// Generates a salt to use with [generateKeyFromPassword]
Future<String> generateSalt();
Future<String?> generateSalt();

/// Encrypts [string] using a [key] generated from [generateRandomKey] or
/// [generateKeyFromPassword]. The returned string is a sequence of 3
/// base64-encoded strings (iv, mac and cipherText) and can be transferred and
/// stored almost anywhere.
Future<String> encrypt(String string, String key);
Future<String?> encrypt(String string, String key);

/// Decrypts [data] created with the [encrypt] method using a [key] created
/// with [generateRandomKey] or [generateKeyFromPassword] methods.
/// In case the [key] is wrong or the [data] has been forged, a
/// [MacMismatchException] is thrown
Future<String> decrypt(String data, String key);
Future<String?> decrypt(String data, String key);
}

/// Implementation of [StringCryptor] using platform channels
class PlatformStringCryptor implements StringCryptor {
static const MethodChannel _channel = const MethodChannel('flutter_string_encryption');

@override
Future<String> decrypt(String data, String key) async {
Future<String?> decrypt(String? data, String? key) async {
try {
final decrypted = await _channel.invokeMethod("decrypt", {
"data": data,
Expand All @@ -50,20 +50,20 @@ class PlatformStringCryptor implements StringCryptor {
}

@override
Future<String> encrypt(String string, String key) async =>
Future<String?> encrypt(String string, String? key) async =>
await _channel.invokeMethod("encrypt", {
"string": string,
"key": key,
});

@override
Future<String> generateRandomKey() async => await _channel.invokeMethod("generate_random_key");
Future<String?> generateRandomKey() async => await _channel.invokeMethod("generate_random_key");

@override
Future<String> generateSalt() async => await _channel.invokeMethod("generate_salt");
Future<String?> generateSalt() async => await _channel.invokeMethod("generate_salt");

@override
Future<String> generateKeyFromPassword(String password, String salt) async =>
Future<String?> generateKeyFromPassword(String password, String salt) async =>
await _channel.invokeMethod("generate_key_from_password", <String, String>{
"password": password,
"salt": salt,
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_string_encryption
description: Cross-platform string encryption using common best-practices.
version: 0.3.1
version: 0.4.1-nullsafety.0
author: Stefano Rodriguez <[email protected]>
homepage: https://github.com/sroddy/flutter_string_encryption

Expand All @@ -9,7 +9,7 @@ dependencies:
sdk: flutter

environment:
sdk: '>=1.24.0 <3.0.0'
sdk: '>=2.12.0 <3.0.0'

# For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/tools/pub/pubspec
Expand Down