dartnative_crypto
RSA and AES cryptography for DartNative — generate keys, encrypt/decrypt, and sign/verify against native crypto. iOS and Android, one API.
Why you'll like it
- RSA, done properly — OAEP and PKCS#1 v1.5 encryption, PSS and PKCS#1 v1.5 signing.
- AES-GCM — authenticated symmetric encryption in two calls.
- Strings or bytes — every RSA op has a
…Bytesvariant for rawUint8List, plus key tooling (generate, PKCS#1 ↔ PKCS#8, derive the public key, PEM-encrypt a private key).
Highlights
RSA.generate(bits)→ anRSAKeyPair(PEM public + private keys).RSA.encryptOAEP/decryptOAEP— OAEP encryption (with…Bytesvariants).RSA.signPSS/verifyPSS(andsignPKCS1v15/verifyPKCS1v15) — signatures.AES.encrypt(data, key)/AES.decrypt(data, key)— AES-GCM.AES.pbkdf2(…)— PBKDF2 key derivation;AES.digest(data, algorithm)— SHA-256/384/512.- RSA key tooling — convert between PKCS#1 / PKCS#8 / PKIX / JWK, derive the public key, PEM-encrypt.
Install
dependencies:
dartnative_crypto: ^1.0.0 # from dartpub.dev
dn pub get
void main() {
DartNativePluginRegistrant.registerAll();
runApp(const MyApp());
}
Quick look
import 'package:dartnative_crypto/dartnative_crypto.dart';
Generate a key pair, then encrypt + decrypt (OAEP):
final pair = await RSA.generate(2048);
final cipher = await RSA.encryptOAEP('hello', '', RSAHash.SHA256, pair.publicKey);
final clear = await RSA.decryptOAEP(cipher, '', RSAHash.SHA256, pair.privateKey);
Sign + verify (PSS):
final sig = await RSA.signPSS('message', RSAHash.SHA256, SaltLength.AUTO, pair.privateKey);
final ok = await RSA.verifyPSS(sig, 'message', RSAHash.SHA256, SaltLength.AUTO, pair.publicKey);
AES-GCM:
final encrypted = await AES.encrypt(data, key); // Uint8List
final decrypted = await AES.decrypt(encrypted, key);
Platform setup
iOS
No native setup required (iOS 13+).
Android
No native setup required (Android API 26+ / Android 8).
Example
The example/ app generates keys and round-trips encrypt/decrypt and
sign/verify — borrow from it freely.
Credits & license
Adapted from flutter-rsa (MIT) and
native-crypto-flutter (MIT),
reworked to FFI.
Commercial plugin distributed via dartpub.dev — file issues on the plugin's page.