Update readme with usage
This commit is contained in:
parent
0d0b0da7dd
commit
6150f4bf36
90
README.md
90
README.md
@ -2,11 +2,20 @@
|
|||||||
|
|
||||||
Fast crypto functions for Flutter.
|
Fast crypto functions for Flutter.
|
||||||
|
|
||||||
|
* Table of content
|
||||||
|
- [Why](#why)
|
||||||
|
- [Performances](#performances)
|
||||||
|
- [How](#how)
|
||||||
|
- [Todo](#todo)
|
||||||
|
- [Installation](#installation)
|
||||||
|
- [Usage](#usage)
|
||||||
|
- [Example](#example)
|
||||||
|
|
||||||
## Why 🤔
|
## Why 🤔
|
||||||
|
|
||||||
Because I faced a performance issue when I was using **PointyCastle**.
|
Because I faced a performance issue when I was using **PointyCastle**.
|
||||||
|
|
||||||
It's quite simple, judge for yourself, these are times for AES256 encryption on an Android device.
|
It's quite simple, judge for yourself, these are times for AES256 encryption on an Android device (**Huawei P30 Pro**).
|
||||||
|
|
||||||
| Size | PointyCastle |
|
| Size | PointyCastle |
|
||||||
|------|--------------|
|
|------|--------------|
|
||||||
@ -24,6 +33,8 @@ It's quite simple, judge for yourself, these are times for AES256 encryption on
|
|||||||
|
|
||||||
## Performances ⏱
|
## Performances ⏱
|
||||||
|
|
||||||
|
On an Android device: **Huawei P30 Pro / Android 10**
|
||||||
|
|
||||||
| Size | NativeCrypto |
|
| Size | NativeCrypto |
|
||||||
|------|--------------|
|
|------|--------------|
|
||||||
| 1 mB | 27 ms
|
| 1 mB | 27 ms
|
||||||
@ -46,12 +57,77 @@ For Android:
|
|||||||
For iOS:
|
For iOS:
|
||||||
|
|
||||||
* [CommonCrypto](https://developer.apple.com/library/archive/documentation/Security/Conceptual/cryptoservices/Introduction/Introduction.html)
|
* [CommonCrypto](https://developer.apple.com/library/archive/documentation/Security/Conceptual/cryptoservices/Introduction/Introduction.html)
|
||||||
* [CryptoKit](https://developer.apple.com/documentation/cryptokit/)
|
|
||||||
|
|
||||||
## Todo 🚀
|
## Todo 🚀
|
||||||
|
|
||||||
* ✅ Implement working cross platform AES encryption/decryption.
|
- [x] Implement working cross platform AES encryption/decryption.
|
||||||
* ✅ Different key sizes support.
|
- [x] Different key sizes support.
|
||||||
* ✅ Improve performances.
|
- [x] Improve performances.
|
||||||
* Add other ciphers.
|
- [ ] Add exceptions.
|
||||||
* ... add asym crypto support.
|
- [ ] PBKDF2 support.
|
||||||
|
- [ ] Add other ciphers.
|
||||||
|
- [ ] ... add asym crypto support.
|
||||||
|
|
||||||
|
## Installation 🚧
|
||||||
|
|
||||||
|
Just add these lines in your **pubspec.yaml**:
|
||||||
|
|
||||||
|
```
|
||||||
|
native_crypto:
|
||||||
|
git:
|
||||||
|
url: https://gogs.pointcheval.fr/hugo/native-crypto-flutter.git
|
||||||
|
ref: v0.0.x
|
||||||
|
```
|
||||||
|
|
||||||
|
> And replace "x" with the current version!
|
||||||
|
|
||||||
|
Then in your code:
|
||||||
|
|
||||||
|
```dart
|
||||||
|
// Symmetric crypto.
|
||||||
|
import 'package:native_crypto/symmetric_crypto.dart';
|
||||||
|
|
||||||
|
// To handle exceptions.
|
||||||
|
import 'package:native_crypto/exceptions.dart';
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage 🎯
|
||||||
|
|
||||||
|
To create an AES instance, and generate a key.
|
||||||
|
```dart
|
||||||
|
AES aes = AES();
|
||||||
|
await aes.init(KeySize.bits256)
|
||||||
|
```
|
||||||
|
|
||||||
|
You can also generate key, then use it in AES.
|
||||||
|
|
||||||
|
```dart
|
||||||
|
Uint8List aeskey = await KeyGenerator().secretKey(keySize: KeySize.bits256);
|
||||||
|
AES aes = AES(key: aeskey);
|
||||||
|
```
|
||||||
|
|
||||||
|
You can create a key with PBKDF2.
|
||||||
|
|
||||||
|
```dart
|
||||||
|
Uint8List key = await KeyGenerator().pbkdf2(password, salt, keyLength: 32, iteration: 10000);
|
||||||
|
AES aes = AES(key: key);
|
||||||
|
```
|
||||||
|
|
||||||
|
Then you can encrypt/decrypt data with this instance.
|
||||||
|
|
||||||
|
```dart
|
||||||
|
encryptedPayload = await aes.encrypt(data);
|
||||||
|
decryptedPayload = await aes.decrypt(encryptedPayload);
|
||||||
|
```
|
||||||
|
|
||||||
|
Or you can also use AES on the fly with different keys.
|
||||||
|
|
||||||
|
```dart
|
||||||
|
Uint8List aeskey = await KeyGenerator().secretKey(keySize: KeySize.bits256);
|
||||||
|
encryptedPayload = await AES().encrypt(data, key: aeskey);
|
||||||
|
decryptedPayload = await AES().decrypt(encryptedPayload, key: aeskey);
|
||||||
|
```
|
||||||
|
|
||||||
|
## Example 📐
|
||||||
|
|
||||||
|
Look in **example/lib/** for an example app.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user