dart_rust_encrypt 2.0.0-dev.0 dart_rust_encrypt: ^2.0.0-dev.0 copied to clipboard
Flutter plugin for commons hashing and encryption algorithms with power of Rust.
example/dart_rust_encrypt_example.dart
import 'dart:convert';
import 'package:dart_rust_encrypt/dart_rust_encrypt.dart';
import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';
import 'package:pointycastle/export.dart';
// If you are running this example locally, you need to pass
// the .so rust build file absolute address (.dylib on mac)
// along with `dart run` like:
/// ```
/// dart run this_example_path.dart dylib_absolute_path.dylib
/// ```
/// For example:
/// ```
/// dart run dart_rust_encrypt_example.dart /Users/[username]/Desktop/dart_rust_encrypt/target/release/libdart_rust_encrypt.dylib
/// ```
void main(List<String> args) async {
createWrapper(ExternalLibrary.open(args[0]));
final input = Uint8List.fromList(utf8.encode('Hello World'));
final salt = Uint8List.fromList(utf8.encode('123456789'));
const iterations = 1024;
const keyLength = 64;
final derivator = PBKDF2KeyDerivator(Mac('SHA3-512/HMAC'))
..reset()
..init(Pbkdf2Parameters(salt, iterations, keyLength));
var pointyOut = derivator.process(input);
var rustOut = await DartRustEncryptAsync.pbkdf2Sha3_512(
input: input,
salt: salt,
iterations: iterations,
keyLength: keyLength,
);
final sha3digest = SHA3Digest(256);
pointyOut = sha3digest.process(pointyOut);
rustOut = await DartRustEncryptAsync.sha3_256(rustOut);
// print('Pointy Castle: \n$pointyOut\n');
// print('Rust: \n$rustOut');
}