Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sync): Add sync methods #86

Merged
merged 4 commits into from
Mar 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 3.8.0
- Add RSASync methods for all Platforms but web

## 3.7.1
- Moved flutter_lints to dev dependencies

Expand Down
156 changes: 126 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,14 @@ Library for use RSA with support for android, ios, macos, windows, linux and web
[![Integration Tests iOS](https://github.com/jerson/flutter-rsa/actions/workflows/tests_ios.yml/badge.svg)](https://github.com/jerson/flutter-rsa/actions/workflows/tests_ios.yml)

[![Integration Tests macOS](https://github.com/jerson/flutter-rsa/actions/workflows/tests_macos.yml/badge.svg)](https://github.com/jerson/flutter-rsa/actions/workflows/tests_macos.yml)

## Contents

- [Fast RSA](#fast-rsa)
- [Contents](#contents)
- [Usage](#usage)
- [Encrypt methods](#encrypt-methods)
- [Decrypt methods](#decrypt-methods)
- [Sign methods](#sign-methods)
- [Verify methods](#verify-methods)
- [Generate Methods](#generate-methods)
- [Convert Methods](#convert-methods)
- [Util Methods](#util-methods)
- [Async methods](#async-methods)
- [Sync methods](#sync-methods)
- [Setup](#setup)
- [Android](#android)
- [iOS](#ios)
Expand All @@ -35,7 +31,9 @@ Library for use RSA with support for android, ios, macos, windows, linux and web

## Usage

### Encrypt methods
### Async Methods

#### Encrypt methods

```dart
import 'package:fast_rsa/fast_rsa.dart';
Expand All @@ -48,7 +46,7 @@ var result = await RSA.encryptPKCS1v15Bytes(messageBytes, publicKey)

```

### Decrypt methods
#### Decrypt methods

```dart
import 'package:fast_rsa/fast_rsa.dart';
Expand All @@ -61,7 +59,7 @@ var result = await RSA.decryptPKCS1v15Bytes(messageBytes, privateKey)

```

### Sign methods
#### Sign methods

```dart
import 'package:fast_rsa/fast_rsa.dart';
Expand All @@ -74,7 +72,7 @@ var result = await RSA.signPKCS1v15Bytes(messageBytes, Hash.SHA256, privateKey)

```

### Verify methods
#### Verify methods

```dart
import 'package:fast_rsa/fast_rsa.dart';
Expand All @@ -87,7 +85,7 @@ var result = await RSA.verifyPKCS1v15Bytes(signatureBytes, messageBytes, Hash.SH

```

### Generate Methods
#### Generate Methods

```dart
import 'package:fast_rsa/fast_rsa.dart';
Expand All @@ -96,38 +94,136 @@ var result = await RSA.generate(2048)

```

### Convert Methods
#### Convert Methods

```dart
import 'package:fast_rsa/fast_rsa.dart';

var result = await RSA.convertJWKToPrivateKey(data, keyId)
var result = await RSA.convertJWKToPublicKey(data, keyId)
var result = await RSA.convertJWKToPrivateKey(data, keyId);
var result = await RSA.convertJWKToPublicKey(data, keyId);

var result = await RSA.convertKeyPairToPKCS12(privateKey, certificate, password)
var result = await RSA.convertPKCS12ToKeyPair(pkcs12, password)
var result = await RSA.convertKeyPairToPKCS12(privateKey, certificate, password);
var result = await RSA.convertPKCS12ToKeyPair(pkcs12, password);

var result = await RSA.convertPrivateKeyToPKCS8(privateKey)
var result = await RSA.convertPrivateKeyToPKCS1(privateKey)
var result = await RSA.convertPrivateKeyToJWK(privateKey)
var result = await RSA.convertPrivateKeyToPKCS8(privateKey);
var result = await RSA.convertPrivateKeyToPKCS1(privateKey);
var result = await RSA.convertPrivateKeyToJWK(privateKey);

var result = await RSA.convertPrivateKeyToPublicKey(privateKey)
var result = await RSA.convertPrivateKeyToPublicKey(privateKey);

var result = await RSA.convertPublicKeyToPKIX(publicKey)
var result = await RSA.convertPublicKeyToPKCS1(publicKey)
var result = await RSA.convertPublicKeyToJWK(publicKey)
var result = await RSA.convertPublicKeyToPKIX(publicKey);
var result = await RSA.convertPublicKeyToPKCS1(publicKey);
var result = await RSA.convertPublicKeyToJWK(publicKey);

var result = await RSA.encryptPrivateKey(privateKey, password, PEMCipher.PEMCIPHER_AES256)
var result = await RSA.decryptPrivateKey(privateKeyEncrypted, password)
var result = await RSA.encryptPrivateKey(privateKey, password, PEMCipher.PEMCIPHER_AES256);
var result = await RSA.decryptPrivateKey(privateKeyEncrypted, password);
```

### Util Methods
#### Util Methods

```dart
import 'package:fast_rsa/fast_rsa.dart';

var result = await RSA.hash(message, Hash.SHA256)
var result = await RSA.base64(message)
var result = await RSA.hash(message, Hash.SHA256);
var result = await RSA.base64(message);

```

### Sync Methods

#### Encrypt methods

```dart
import 'package:fast_rsa/fast_rsa_sync.dart';

var result = RSASync.encryptOAEP(message, label, Hash.HASH_SHA256, publicKey);
var result = RSASync.encryptPKCS1v15(message, publicKey);

var result = RSASync.encryptOAEPBytes(messageBytes, label, Hash.SHA256, publicKey);
var result = RSASync.encryptPKCS1v15Bytes(messageBytes, publicKey);

```

#### Decrypt methods

```dart
import 'package:fast_rsa/fast_rsa_sync.dart';

var result = RSASync.decryptOAEP(message, label, Hash.HASH_SHA256, privateKey);
var result = RSASync.decryptPKCS1v15(message, privateKey);

var result = RSASync.decryptOAEPBytes(messageBytes, label, Hash.SHA256, privateKey);
var result = RSASync.decryptPKCS1v15Bytes(messageBytes, privateKey);

```

#### Sign methods

```dart
import 'package:fast_rsa/fast_rsa_sync.dart';

var result = RSASync.signPSS(message, Hash.SHA256, SaltLength.SALTLENGTH_AUTO, privateKey);
var result = RSASync.signPKCS1v15(message, Hash.SHA256, privateKey);

var result = RSASync.signPSSBytes(messageBytes, Hash.SHA256, SaltLength.SALTLENGTH_AUTO, privateKey);
var result = RSASync.signPKCS1v15Bytes(messageBytes, Hash.SHA256, privateKey);

```

#### Verify methods

```dart
import 'package:fast_rsa/fast_rsa_sync.dart';

var result = RSASync.verifyPSS(signature, message, Hash.SHA256, SaltLength.SALTLENGTH_AUTO, publicKey);
var result = RSASync.verifyPKCS1v15(signature, message, Hash.SHA256, publicKey);

var result = RSASync.verifyPSSBytes(signatureBytes, messageBytes, Hash.SHA256, SaltLength.SALTLENGTH_AUTO, publicKey);
var result = RSASync.verifyPKCS1v15Bytes(signatureBytes, messageBytes, Hash.SHA256, publicKey);

```

#### Generate Methods

```dart
import 'package:fast_rsa/fast_rsa_sync.dart';

var result = RSASync.generate(2048)

```

#### Convert Methods

```dart
import 'package:fast_rsa/fast_rsa_sync.dart';

var result = RSASync.convertJWKToPrivateKey(data, keyId);
var result = RSASync.convertJWKToPublicKey(data, keyId);

var result = RSASync.convertKeyPairToPKCS12(privateKey, certificate, password);
var result = RSASync.convertPKCS12ToKeyPair(pkcs12, password);

var result = RSASync.convertPrivateKeyToPKCS8(privateKey);
var result = RSASync.convertPrivateKeyToPKCS1(privateKey);
var result = RSASync.convertPrivateKeyToJWK(privateKey);

var result = RSASync.convertPrivateKeyToPublicKey(privateKey);

var result = RSASync.convertPublicKeyToPKIX(publicKey);
var result = RSASync.convertPublicKeyToPKCS1(publicKey);
var result = RSASync.convertPublicKeyToJWK(publicKey);

var result = RSASync.encryptPrivateKey(privateKey, password, PEMCipher.PEMCIPHER_AES256);
var result = RSASync.decryptPrivateKey(privateKeyEncrypted, password);
```

#### Util Methods

```dart
import 'package:fast_rsa/fast_rsa_sync.dart';

var result = RSASync.hash(message, Hash.SHA256);
var result = RSASync.base64(message);

```

Expand Down
1 change: 1 addition & 0 deletions example/android/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ GeneratedPluginRegistrant.java
key.properties
**/*.keystore
**/*.jks
.cxx
4 changes: 2 additions & 2 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/integration_test/ios"

SPEC CHECKSUMS:
fast_rsa: 47058fe497c032937a8e259e99ddf6255fa67238
fast_rsa: f8430fbf47ba59e7ef2fd84a12f5f391d1086727
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
integration_test: 252f60fa39af5e17c3aa9899d35d908a0721b573
integration_test: 4a889634ef21a45d28d50d622cf412dc6d9f586e

PODFILE CHECKSUM: 819463e6a0290f5a72f145ba7cde16e8b6ef0796

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
enableGPUValidationMode = "1"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
Expand Down
1 change: 1 addition & 0 deletions example/lib/generate.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:fast_rsa/fast_rsa.dart';
import 'package:fast_rsa/fast_rsa_sync.dart';

import 'package:fast_rsa_example/shared/button_widget.dart';
import 'package:fast_rsa_example/shared/title_widget.dart';
Expand Down
2 changes: 1 addition & 1 deletion example/macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ EXTERNAL SOURCES:
:path: Flutter/ephemeral

SPEC CHECKSUMS:
fast_rsa: 47a50bec1042c8c01726007dc0590a078418f997
fast_rsa: 940a67b8d8e425f37708189361efc90be7299d66
FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24

PODFILE CHECKSUM: 236401fc2c932af29a9fcf0e97baeeb2d750d367
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
enableGPUValidationMode = "1"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
Expand Down
4 changes: 4 additions & 0 deletions example/macos/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ class AppDelegate: FlutterAppDelegate {
override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
return true
}

override func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool {
return true
}
}
Loading
Loading