cryptum_dart 0.0.4
SDKdartflutter
Platformandroidioswindowslinuxmacosweb
A Dart port of the Cryptum encryption library providing hybrid RSA/AES-GCM encryption with secure session key handling and dynamic format negotiation.
Cryptum Example
This example demonstrates the core functionality of the Cryptum package for secure message encryption and decryption.
Features Demonstrated
- Key pair generation
- Message encryption and decryption
- Message format handling
- Error handling for format mismatches
- Tamper detection
Code Walkthrough
The example simulates a secure message exchange between two parties (Alice and Bob):
- Initialize Cryptum Instances
final alice = Cryptum();
final bob = Cryptum();
- Generate Key Pairs
final aliceKeys = await alice.generateKey();
final bobKeys = await bob.generateKey();
- Create and Format Message
final message = 'Hello, this is a secret message!';
final messageBytes = Uint8List.fromList(utf8.encode(message));
- Generate Message Formats
final aliceFormat = MessageFormat.generateRandom();
final bobFormat = MessageFormat.generateRandom();
- Encrypt Message
final encrypted = await alice.encryptBlob(
messageBytes,
bobKeys['public']!,
format: aliceFormat,
);
- Decrypt Message
final decrypted = await bob.decryptBlob(
encrypted,
bobKeys['private']!,
format: aliceFormat,
);
The example also includes error handling demonstrations for:
- Using mismatched message formats
- Attempting to decrypt messages with incorrect keys
Running the Example
To run this example:
- Ensure you have the Cryptum package added to your
pubspec.yaml:
dependencies:
cryptum_dart: ^1.0.0
- Run the example:
dart run example/cryptum_example.dart