Lazysecret is a comprehensive Flutter implementation of the libsodium using secret_box library.
- pubspec.yml
dependencies:
lazysecret: ^1.0.2
- Dart
final lazysecret = LazySecret.instance;
Future<Uint8List> randomBytesBuf(int size)
Future<String> toHex(Uint8List bytes)
Future<Uint8List> toBin(String hexString)
Future<String> cryptoBoxBeforeNm(KeyPair keyPair)
Future<String> cryptoSecretBoxEasy(String plaintext, String nonce, String key)
Future<String> cryptoSecretBoxOpenEasy(String ciphertext, String nonce, String key)
Future<KeyPair> cryptoKxKeyPair()
Future<int> cryptoSecretBoxKeyBytes()
Future<int> cryptoSecretBoxNonceBytes()
Future<int> cryptoSecretBoxMacBytes()
- proguard-rules.pro
-keep class com.sun.jna.** { *; }
-keep class * implements com.sun.jna.** { *; }
-dontwarn java.awt.*
-keepclassmembers class * extends com.sun.jna.* { public *; }
-keepclassmembers class * extends com.sun.jna.** {
<fields>;
<methods>;
}
- Download the
sodium.js
file
https://raw.githubusercontent.com/jedisct1/libsodium.js/master/dist/browsers-sumo/sodium.js
- Add
sodium.js
toweb
directory
.
└── web
├── ...
└── sodium.js <- here
- Add script in
web/index.html
<script src="sodium.js"></script>
- Add
LazySecret.init()
inmain.dart
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await LazySecret.init();
runApp(const MyApp());
}
https://libsodium.gitbook.io/doc/secret-key_cryptography/secretbox
Sodium is a modern, easy-to-use software library for encryption, decryption, signatures, password hashing, and more.