Skip to content

Commit 44a4d86

Browse files
authored
Update README.md
1 parent 51e730c commit 44a4d86

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

README.md

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
1-
# rsa_key_generator
1+
# Flutter RSA Key Generator
22

3-
Flutter app to generate RSA keys
3+
This project shows how to use [Pointy Castle](https://github.com/PointyCastle/pointycastle) to generate a RSA Key and encode it to a PKCS1 Pem String.
44

5-
## Getting Started
5+
![](rsa_generator.gif)
66

7-
This project is a starting point for a Flutter application.
7+
In order to generate a new `RSA Keypair` we use `RSAKeyGenerator`
88

9-
A few resources to get you started if this is your first Flutter project:
9+
```
10+
AsymmetricKeyPair<PublicKey, PrivateKey> computeRSAKeyPair(
11+
SecureRandom secureRandom) {
12+
var rsapars = new RSAKeyGeneratorParameters(BigInt.from(65537), 2048, 12);
13+
var params = new ParametersWithRandom(rsapars, secureRandom);
14+
var keyGenerator = new RSAKeyGenerator();
15+
keyGenerator.init(params);
16+
return keyGenerator.generateKeyPair();
17+
}
18+
```
1019

11-
- [Lab: Write your first Flutter app](https://flutter.io/docs/get-started/codelab)
12-
- [Cookbook: Useful Flutter samples](https://flutter.io/docs/cookbook)
20+
To be able generate the keys in a background thread we use Dart's [Isolate](https://api.dartlang.org/stable/2.1.0/dart-isolate/dart-isolate-library.html) implemented in Flutter's [compute](https://docs.flutter.io/flutter/foundation/compute.html). We must ensure that the `computeRSAKeyPair` function is placed __outside__ a `Class` so that it can be called globally.
1321

14-
For help getting started with Flutter, view our
15-
[online documentation](https://flutter.io/docs), which offers tutorials,
16-
samples, guidance on mobile development, and a full API reference.
22+
```
23+
Future<AsymmetricKeyPair<PublicKey, PrivateKey>> getRSAKeyPair(
24+
SecureRandom secureRandom) async {
25+
return await compute(computeRSAKeyPair, secureRandom);
26+
}
27+
```

0 commit comments

Comments
 (0)