dart_rust_encrypt 1.2.1+2 dart_rust_encrypt: ^1.2.1+2 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 'dart:ffi';
import 'dart:typed_data';
import 'package:dart_rust_encrypt/dart_rust_encrypt.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 {
final input = Uint8List.fromList(utf8.encode('Hello World'));
final salt = Uint8List.fromList(utf8.encode('123456789'));
const iterations = 1024;
const keyLength = 64;
final dartRustEncrypt = createWrapper(DynamicLibrary.open(args[0]));
final derivator = PBKDF2KeyDerivator(Mac('SHA3-512/HMAC'))
..reset()
..init(Pbkdf2Parameters(salt, iterations, keyLength));
var pointyOut = derivator.process(input);
var rustOut = await dartRustEncrypt.pbkdf2_Sha3_512(
input: input,
salt: salt,
iterations: iterations,
keyLength: keyLength,
);
final sha3digest = SHA3Digest(256);
pointyOut = sha3digest.process(pointyOut);
rustOut = await dartRustEncrypt.sha3_256(rustOut);
// print('Pointy Castle: \n$pointyOut\n');
// print('Rust: \n$rustOut');
}