Code Monkey home page Code Monkey logo

jerson / flutter-rsa Goto Github PK

View Code? Open in Web Editor NEW
67.0 6.0 20.0 283.25 MB

RSA for flutter made with golang for fast performance with support for android, ios, macos, linux, windows, web and hover

Home Page: https://pub.dev/packages/fast_rsa

License: MIT License

Ruby 1.66% Objective-C 0.23% Dart 67.12% HTML 0.52% C 5.97% JavaScript 6.20% C++ 9.70% Swift 0.76% Shell 1.18% CMake 6.05% Makefile 0.10% Dockerfile 0.10% Java 0.42%
golang rsa flutter xcode android ios encrypt decrypt sign pss

flutter-rsa's Introduction

Fast RSA

Library for use RSA with support for android, ios, macos, windows, linux and web

Integration Tests Android

Integration Tests Linux

Integration Tests Windows

Integration Tests iOS

Integration Tests macOS

Contents

Usage

Encrypt methods

import 'package:fast_rsa/fast_rsa.dart';

var result = await RSA.encryptOAEP(message, label, Hash.HASH_SHA256, publicKey)
var result = await RSA.encryptPKCS1v15(message, publicKey)

var result = await RSA.encryptOAEPBytes(messageBytes, label, Hash.SHA256, publicKey)
var result = await RSA.encryptPKCS1v15Bytes(messageBytes, publicKey)

Decrypt methods

import 'package:fast_rsa/fast_rsa.dart';

var result = await RSA.decryptOAEP(message, label, Hash.HASH_SHA256, privateKey)
var result = await RSA.decryptPKCS1v15(message, privateKey)

var result = await RSA.decryptOAEPBytes(messageBytes, label, Hash.SHA256, privateKey)
var result = await RSA.decryptPKCS1v15Bytes(messageBytes, privateKey)

Sign methods

import 'package:fast_rsa/fast_rsa.dart';

var result = await RSA.signPSS(message, Hash.SHA256, SaltLength.SALTLENGTH_AUTO, privateKey)
var result = await RSA.signPKCS1v15(message, Hash.SHA256, privateKey)

var result = await RSA.signPSSBytes(messageBytes, Hash.SHA256, SaltLength.SALTLENGTH_AUTO, privateKey)
var result = await RSA.signPKCS1v15Bytes(messageBytes, Hash.SHA256, privateKey)

Verify methods

import 'package:fast_rsa/fast_rsa.dart';

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

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

Generate Methods

import 'package:fast_rsa/fast_rsa.dart';

var result = await RSA.generate(2048)

Convert Methods

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.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.convertPrivateKeyToPublicKey(privateKey)

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)

Util Methods

import 'package:fast_rsa/fast_rsa.dart';

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

Setup

Android

No additional setup required.

iOS

No additional setup required.

Web

add to you pubspec.yaml

assets:
  - packages/fast_rsa/web/assets/worker.js
  - packages/fast_rsa/web/assets/wasm_exec.js
  - packages/fast_rsa/web/assets/rsa.wasm

ref: https://github.com/jerson/flutter-rsa/blob/master/example/pubspec.yaml

MacOS

no additional setup required

Linux

No additional setup required.

Windows

No additional setup required.

Example

Inside example folder

cd example && flutter run

check our web demo: [https://flutter-rsa.jerson.dev/]

Native Code

the native library is made in Golang and build with gomobile for faster performance

https://github.com/jerson/rsa-mobile

flutter-rsa's People

Contributors

crisscm avatar jerson avatar martingeorgiu avatar nilsreichardt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

flutter-rsa's Issues

Encryption fails on Safari

Hey,

we use this in our app and it works great in web and mobile - except on Safari (mobile and desktop).

Here's a screenshot of the respective error in the JS console:

image

In our code we're essentially doing this:

return await RSA.encryptPKCS1v15(message, publicKey);

Error when publishing app to App Store Connect: `Contents/Frameworks/fast_rsa.framework/Versions/A/Resources/librsa_bridge.dylib has following signing error(s): code object is not signed at all In architecture: x86_64`

Description

When we publish our macOS app to App Store Connect, we get the following email by Apple:

Dear Developer,

We identified one or more issues with a recent delivery for your app, "Sharezone - Schulplaner" 1.6.2 (412). Please correct the following issues, then upload again.

ITMS-90238: Invalid Signature - The executable at path Sharezone.app/Contents/Frameworks/fast_rsa.framework/Versions/A/Resources/librsa_bridge.dylib has following signing error(s): code object is not signed at all In architecture: x86_64 . Refer to the Code Signing and Application Sandboxing Guide at http://developer.apple.com/library/mac/#documentation/Security/Conceptual/CodeSigningGuide/AboutCS/AboutCS.html and Technical Note 2206 at https://developer.apple.com/library/mac/technotes/tn2206/_index.html for more information.

Best regards,

The App Store Team

I am not sure if someone knows how to fix it. I'm sure we're doing something wrong with signing (see the signing code in "Our code") because when publishing with our MacBook to App Store Connect, everything works.

Details

  • It only happens when we publish our macOS app, our iOS app is fine
  • It only happens when publishing with our CD, not publishing with our MacBook via XCode

"Steps to reproduce"

These are steps that we executed:

  1. Followed the docs by Flutter to publish a macOS App: https://docs.flutter.dev/deployment/macos#create-a-build-archive-with-codemagic-cli-tools
  2. Publish the app to App Store Connect

Our code

APP_NAME=$(find $(pwd) -name "*.app")
PACKAGE_NAME=$(basename "$APP_NAME" .app).pkg
xcrun productbuild --component "$APP_NAME" /Applications/ unsigned.pkg

INSTALLER_CERT_NAME=$(keychain list-certificates \
          | jq '[.[]
            | select(.common_name
            | contains("Mac Developer Installer"))
            | .common_name][0]' \
          | xargs)

xcrun productsign --sign "$INSTALLER_CERT_NAME" unsigned.pkg "$PACKAGE_NAME"
rm -f unsigned.pkg

Our GitHub Actions workflow: https://github.com/SharezoneApp/sharezone-app/blob/6c376fe1b7898085b5f0f0af819b6bd942176daf/.github/workflows/safe_app_ci.yml
Our app code: https://github.com/SharezoneApp/sharezone-app/tree/add-alpha-macos/app

Environment

  • Flutter version: 3.7.12
  • fast_rsa version: 3.5.7
  • Used GitHub Actions with macos-13 to build and sign the app

Failed to load dynamic library '.../librsa_bridge.so'

My Flutter app distributed on the Google Play store seems to be unable to load a packaged dynamic library on a few Android devices (less than Android 6.0).

Actual results:
Failed to load dynamic library '/data/data/my_package/lib/librsa_bridge.so': dlopen failed: '/data/data/my_package/lib/librsa_bridge.so' not found

Expected results:
The library is loaded successfully.

Flutter doctor output

Doctor summary (to see all details, run flutter doctor -v):
[โœ“] Flutter (Channel unknown, 2.10.3, on macOS 13.0 22A380 darwin-x64, locale en-VN)
[โœ“] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
[โœ“] Xcode - develop for iOS and macOS (Xcode 14.1)
[โœ“] Chrome - develop for the web
[โœ“] Android Studio (version 2021.3)
[โœ“] VS Code (version 1.73.1)
[โœ“] Connected device (2 available)
[โœ“] HTTP Host Availability

โ€ข No issues found!

Xcode 15 beta 5 - Multiple errors

Description

Using Xcode 15 beta 5, I get the following error for lib fast_rsa:

Environment
Flutter version: 3.7.12
fast_rsa version: 3.5.7 or below
With mac Os chip M2

When trying to build the project

ld: warning: '../fast_rsa/ios/librsa_bridge.a[x86_64][2]( go.o )' has malformed LC_DYSYMTAB, expected 52 undefined symbols to start at index 6997, found 64 undefined symbols starting at index 56
ld: warning: '../fast_rsa/ios/librsa_bridge.a[x86_64][2](go.o)' has malformed LC_DYSYMTAB, expected 52 undefined symbols to start at index 6997, found 64 undefined symbols starting at index 56

ld: multiple errors: initializer pointer must point to start of function (no addend) in '../fast_rsa/ios/librsa_bridge.a[x86_64][2](go.o)'; initializer pointer must point to start of function (no addend) in '../fast_rsa/ios/librsa_bridge.a[x86_64][2](go.o)'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I found this issue related but the proposed solution didn't work for me issue related Xcode 15 beta

Signature Verification Failure, can not do RSA.verifyPSS if change device

Title:
Signature Verification Failure Issue

Description:
Background: I encountered an issue while using your library. I'm developing an application that involves data signing using fast_rsa.

Steps to Reproduce:

  1. Sign data Y using key X.private on Device A, generating signature Z.
  2. Copy the application from Device A to Device B.
  3. Attempt to verify signature Z as the signature of data Y using the same key X.public on Device B.

Expected Result: I expect the signature Z to be successfully verified on Device B, just like it is on Device A.

Actual Result: However, on Device B, the verification of signature Z fails.

Device and Environment Information:

  • Device A: Physical device Android 9
  • Device B: android-x89 emulator Android 9
  • Library Version: fast_rsa: ^3.6.1

Attempted Solutions:
I have tried regenerating the key pair and reinstalling the library, but the issue persists.

Code:
Future sign(String value) async {
var signature = await RSA.signPSS(
value, Hash.SHA512, SaltLength.AUTO, pkcs12KeyPair.privateKey);
var result = signature.replaceAll("+", "-").replaceAll("/", "
");
return result;
}

Future verifySign(String value, String sign) async {
sign = sign.replaceAll("-", "+").replaceAll("_", "/");
try {
await RSA.verifyPSS(
sign, value, Hash.SHA512, SaltLength.AUTO, _pkcs12KeyPair.publicKey);
} on RSAException catch (error, stackTrace) {
debugPrint(error.cause);
debugPrintStack(stackTrace: stackTrace);
return false;
}
return true;
}

** Exception **
I/flutter (13473): crypto/rsa: verification error
I/flutter (13473): #0 RSA._boolResponse
fast_rsa.dart:71
I/flutter (13473):
I/flutter (13473): #1 RSA.verifyPSS
fast_rsa.dart:374
I/flutter (13473):

Expected Result: I hope to achieve successful signature verification on Device B, similar to the behavior on Device A.

Actual Result: However, the signature verification fails on Device B.

flutter doctor -v
[โˆš] Flutter (Channel stable, 3.10.6, on Microsoft Windows [็‰ˆๆœฌ 10.0.22621.2134], locale fr-FR)
โ€ข Flutter version 3.10.6 on channel stable at C:\flutter
โ€ข Upstream repository https://github.com/flutter/flutter.git
โ€ข Framework revision f468f3366c (6 weeks ago), 2023-07-12 15:19:05 -0700
โ€ข Engine revision cdbeda788a
โ€ข Dart version 3.0.6
โ€ข DevTools version 2.23.1

[โˆš] Windows Version (Installed version of Windows is version 10 or higher)

[โˆš] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
โ€ข Android SDK at C:\Users\cc\AppData\Local\Android\sdk
โ€ข Platform android-33-ext5, build-tools 33.0.2
โ€ข Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
โ€ข Java version openjdk version "17.0.6" 2023-01-17
โ€ข All Android licenses accepted.

[โˆš] Chrome - develop for the web
โ€ข Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[โˆš] Visual Studio - develop for Windows (Visual Studio Community 2022 17.5.4)
โ€ข Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
โ€ข Visual Studio Community 2022 version 17.5.33530.505
โ€ข Windows 10 SDK version 10.0.19041.0

[โˆš] Android Studio (version 2022.2)
โ€ข Android Studio at C:\Program Files\Android\Android Studio
โ€ข Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
โ€ข Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
โ€ข Java version openjdk version "17.0.6" 2023-01-17

[โˆš] VS Code (version 1.81.1)
โ€ข VS Code at C:\Users\cc\AppData\Local\Programs\Microsoft VS Code
โ€ข Flutter extension version 3.70.0

[โˆš] Connected device (4 available)
โ€ข Android SDK built for x86 (mobile) โ€ข emulator-5554 โ€ข android-x86 โ€ข Android 11 (API 30) (emulator)
โ€ข Windows (desktop) โ€ข windows โ€ข windows-x64 โ€ข Microsoft Windows [็‰ˆๆœฌ 10.0.22621.2134]
โ€ข Chrome (web) โ€ข chrome โ€ข web-javascript โ€ข Google Chrome 115.0.5790.171
โ€ข Edge (web) โ€ข edge โ€ข web-javascript โ€ข Microsoft Edge 116.0.1938.54

[โˆš] Network resources
โ€ข All expected network resources are available.

โ€ข No issues found!

Seed Key Generator?

Is there anyway to seed the RSA key generator? I am looking to seed it to produce the same key pair based on a hashed password. Is there anyway to do that with this package? The reason is I need a way for users to be able to generate the same key pair on multiple devices without having to share it explicitly. My idea being when they sign in on a new device I can generate their keypair based on their hashed password. Let me know if there is a better way I should do this. Thanks.

infinity waiting when rsa sign

Hi, I have a strange problem here. When I use the RSA SignPSS feature, there is an infinite wait.
I use Android Studio, use usb cable connect with my Samsung Tab7.
If I start program on device, keep usb cable connect, the function always ok,
but, when I start program, and then disconnect the usb cable, the signPSS could not return result.
here is my code :

final _pkcs12KeyPair = await RSA.convertPKCS12ToKeyPair(
    (await rootBundle.loadString('assets/key.base64')), "miipos");
var signature = await RSA.signPSS(
    value, Hash.SHA512, SaltLength.AUTO, _pkcs12KeyPair.privateKey); // always waiting there, never return the result signature

var result = signature.replaceAll("+", "-").replaceAll("/", "_");
debugPrint(result);
debugPrint("****** end sign ******");

thanks

flutter web : rsa.wasm size optimization

I think this plugin is fantastic very good!
But the flutter web package rsa.wasm is too big, can it be optimized?
It is also good to provide ideas.
It was a difficult thing for me to optimize it for the first time.
Thanks!

`Execution failed for task ':fast_rsa:stripReleaseDebugSymbols'` when building for Android

Description

We have the problem that we can't build anymore for our CI. When we try to build with Codemagic or GitHub Actions, we get this error:

* What went wrong:
Execution failed for task ':fast_rsa:stripReleaseDebugSymbols'.
> 1 exception was raised by workers:
  org.gradle.process.internal.ExecException: A problem occurred starting process 'command '/usr/local/share/android-sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-strip''

GitHub Actions logs:

Source code of our app: https://github.com/SharezoneApp/sharezone-app

We are using version 3.4.7 of fast_rsa and 2.10.5 of Flutter.

Illegal base64 letter at input byte 4

What i want to do is pretty simple

var keys = await RSA.generate(2048);
_ourPrivateKey = keys.privateKey;
_ourPublicKey = keys.publicKey;

// Application 1
var enc = await RSA.encryptOAEP(message, "yes", Hash.SHA256, _ourPublicKey);

// at this point the message has arrived on Application 2
var dec = await RSA.decryptOAEP(message, "yes", Hash.SHA256, _ourPrivateKey);

But it throws RSAException - Illegal base64 letter at input byte 4

The public keys being negotiated between the applications are correct

support for binary key import/export

I appreciate having another RSA library available :)
I was surprised at the focus with keys being in a string format. The other crypto libraries i'm familiar with default to binary keys. Does your underlying native code support binary? Maybe i'll contribute and do a pull request.

Using generated public key in golang

Background :

For RSA private key & public key PKCS1, PKCS8 & PKCS1, PKIX formats are available.
PKCS1 format is primarily only used for the RSA algorithm and they have different headers.

private key PKCS1 format header : -----BEGIN RSA PRIVATE KEY-----
private key PKCS8 format header : -----BEGIN PRIVATE KEY-----

public key PKCS1 format header : -----BEGIN RSA PUBLIC KEY-----
public key PKIX format header : -----BEGIN PUBLIC KEY-----

ref : https://pkg.go.dev/crypto/rsa

Problem :

The generated public key is in PKIX format and it can not be parsed in Golang (using standard lib for RSA)
and by changing the header to PKCS1 format (as golang indicates in its error) it can be parsed but the encrypted data can not be decrypted by its own private key.

Steps to Reproduce :

Here is a Golang code snippet for parsing public key in both PKIX&PKCS1 formats and encrypting some plain text data.
You can generate a new key pair in dart/flutter and run this code snippet online to parse & encrypt by the generated public key
And try to decrypt the result again in dart/flutter.

https://go.dev/play/p/4D9ej_jszsU

RSA.generate in Browser: Refused to execute script... MIME type ('text/html') is not executable

Thank your for the library!

Is it supposed to work in a web environment?

Running this code in the latest Chrome results in the error below.

Debug mode.

await fast.RSA.generate(2048);
Refused to execute script from 'http://localhost:63079/assets/packages/fast_rsa/web/assets/worker.js' 
because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.

Deployed to a server this error occurs:

main.dart.js:5146 Uncaught MissingPluginException(No implementation found for method generate on channel fast_rsa)
    at Object.c (https://XXXXXXXXXX/main.dart.js:5146:19)
    at https://XXXXXXXXXX/main.dart.js:89698:15
    at aWO.a (https://XXXXXXXXXX/main.dart.js:6521:63)
    at aWO.$2 (https://XXXXXXXXXX/main.dart.js:50328:14)
    at aVt.$1 (https://XXXXXXXXXX/main.dart.js:50322:21)
    at aSg.aKJ (https://XXXXXXXXXX/main.dart.js:51171:34)
    at aSg.B8 (https://XXXXXXXXXX/main.dart.js:51174:13)
    at aOx.$0 (https://XXXXXXXXXX/main.dart.js:50750:11)
    at Object.Ca (https://XXXXXXXXXX/main.dart.js:6653:40)
    at ax.tA (https://XXXXXXXXXX/main.dart.js:50685:3)

[Bug] DLL load fails in unit test

In my flutter app I have unit tests which call into fast_rsa. However, the tests fail to load librsa_bridge.dll.

Example: rsa_test.dart

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

void main() {
  test("RSA", () async {
    await RSA.generate(2048);
  });
}

Error:

Invalid argument(s): Failed to load dynamic library 'librsa_bridge.dll': error code 126
dart:ffi                                     new DynamicLibrary.open
package:fast_rsa/bridge/binding.dart 119:33  Binding.openLib
package:fast_rsa/bridge/binding.dart 25:16   new Binding._internal
package:fast_rsa/bridge/binding.dart 16:45   Binding._singleton
package:fast_rsa/bridge/binding.dart         Binding._singleton
package:fast_rsa/bridge/binding.dart 21:12   new Binding
package:fast_rsa/fast_rsa.dart 38:32         RSA.bindingEnabled
package:fast_rsa/fast_rsa.dart               RSA.bindingEnabled
package:fast_rsa/fast_rsa.dart 41:9          RSA._call
package:fast_rsa/fast_rsa.dart 77:22         RSA._keyPairResponse
package:fast_rsa/fast_rsa.dart 435:18        RSA.generate
test\rsa_test.dart 6:15                      main.<fn>
test\rsa_test.dart 5:15                      main.<fn>

`RSA.decryptPrivateKey()` no result

Sometimes I face the issue that my code just gets stuck on RSA.decryptPrivateKey() call and never continues.
For me it looks like this MR caused this problem. It looks like there is an unhandled error in c++ code which is not sent through the port.
And since onExit and onError callbacks of Isolate.spawn() were removed, method never returns anything.
Moreover, it started happening after upgrading plugin from 3.5.1 to 3.6.1

Could you please inspect code of the RSA.decryptPrivateKey() method to check for errors handling?
Sorry, for now I cannot provide the actual key-password pair to reproduce this issue. It happens rarely (I use key returned from the BE) and I added more logs to the code. So if you won't find anything suspicious in c++ code, I hope I will catch the data and will be able to provide an example to reproduce the issue.

decrypting with an invalid private key caused a panic and the app crashed.

Hello

I am making an application that encrypts and decrypts using fast rsa.
but, decrypting with an invalid private key caused a panic and the app crashed.
I want to handle it as an exception when I specify an invalid private key.

      KeyPair keyPair = await RSA.generate(2048);
      String plainText = "ABCDEFG";
      var ciphertext = await RSA.encryptPKCS1v15(plainText, keyPair.publicKey);

      // case 1. OK
      var result = await RSA.decryptPKCS1v15(ciphertext, keyPair.privateKey);
      plainText == result ? print("OK") : print("NG");

      // case 2. NG  "panic: runtime error: invalid memory address or nil pointer dereference" was output to the console
      result = await RSA.decryptPKCS1v15(ciphertext, "hogehogehoge");
      plainText == result ? print("OK") : print("NG");

enviroment

  • Android Studio 3.6.3
  • Flutter 1.22.4
  • Dart 2.10.4
  • fast rsa 1.3.2 (fast_rsa: ^1.3.2)

E/Go ( 5587): panic: runtime error: invalid memory address or nil pointer dereference
E/Go ( 5587): [signal SIGSEGV: segmentation violation code=0x1 addr=0xc pc=0xa9eef31a]
E/Go ( 5587):
E/Go ( 5587): goroutine 17 [running, locked to thread]:
E/Go ( 5587): github.com/jerson/rsa-mobile/rsa.(*FastRSA).readPrivateKey(0x7982ee7b, 0x79816150, 0xc, 0x169, 0x0, 0x0)
E/Go ( 5587): /home/runner/work/rsa-mobile/rsa-mobile/rsa/common.go:17 +0x5a
E/Go ( 5587): github.com/jerson/rsa-mobile/rsa.(*FastRSA).decryptPKCS1v15(0x7982ee7b, 0x799aab40, 0x100, 0x102, 0x79816150, 0xc, 0x0, 0x0, 0x7989c5e0, 0x0, ...)
E/Go ( 5587): /home/runner/work/rsa-mobile/rsa-mobile/rsa/decrypt_pkcsv15.go:29 +0x36
E/Go ( 5587): github.com/jerson/rsa-mobile/rsa.(*FastRSA).DecryptPKCS1v15(0x7982ee7b, 0x799802c0, 0x158, 0x79816150, 0xc, 0x0, 0x0, 0x79820000, 0xd3bd96d0)
E/Go ( 5587): /home/runner/work/rsa-mobile/rsa-mobile/rsa/decrypt_pkcsv15.go:15 +0x83
E/Go ( 5587): github.com/jerson/rsa-mobile/bridge.instance.decryptPKCS1v15(0x7982ee7b, 0x799ac000, 0x169, 0x169, 0x799ac000, 0xe64c9de0)
E/Go ( 5587): /home/runner/work/rsa-mobile/rsa-mobile/bridge/call.go:347 +0x102
E/Go ( 5587): github.com/jerson/rsa-mobile/bridge.Call(0x79816140, 0xf, 0x799ac000, 0x169, 0x169, 0x1, 0x0, 0xa9f7be60, 0xa9bdbff2, 0x79890030)
E/Go ( 5587): /home/runner/work/rsa-mobile/rsa-mobile/bridge/call.go:43 +0x42b
E/Go ( 5587): main.RSABridgeCall(0xd3bd96d0, 0xe64c9de0, 0x169, 0x0)
E/Go ( 5587): /home/runner/work/rsa-mobile/rsa-mobile/binding/main.go:17 +0x7b
E/Go ( 5587): main._cgoexpwrap_0aae0d41709f_RSABridgeCall(0xd3bd96d0, 0xe64c9de0, 0x169, 0x0)
E/Go ( 5587): _cgo_gotypes.go:106 +0x69
F/libc ( 5587): Fatal signal 6 (SIGABRT), code -6 (SI_TKILL) in tid 5908 (DartWorker), pid 5587 (er.app.password)


Unable to load asset on iOS

If I try to run my debug flutter application on my device, I get following error on iOS:

Caught error: Unable to load asset: /private/var/containers/Bundle/Application/E8B1597B-8CCB-4A34-B147-48E683C039C9/Runner.app/assets/locale/locale_de.json

If I remove the entry

fast_rsa: ^1.3.6

from my pubspec.yaml and all related source code everything works fine. On Android Fast RSA works without this issue.

sign pre-hashed data

Hi, I want to sign some hashed data, but the corresponding function of the fast_rsa hash it by force. My problem is that I need to sign pre-hashed data. I think it would be a great idea if the signing pre-hashed data feature were added to the library (like NONEwithRSA in java).

Failed to load dynamic library 'librsa_bridge.dylib'

I am trying to test some functions using Mockito, but when I try to call it, it throws an error. It works fine in the application itself, but in the tests don't.

This is the test:

test('Public and private key should not be null when generated', () async {
      final MockRSAKeysProvider rsaKeys = MockRSAKeysProvider();

      when(rsaKeys.generate(any)).thenAnswer((value) async {
        KeyPair keyPair = await RSA.generate(2048);
        rsaKeys.setKeyPair = keyPair;
      });

      await rsaKeys.generate('2048');

      verify(rsaKeys.notifyListeners()).called(1);
      expect(rsaKeys.keyPair?.privateKey, isNotNull);
      expect(rsaKeys.keyPair?.publicKey, isNotNull);
    });

This is the code I am testing:

class RSAKeysProvider with ChangeNotifier {
 KeyPair? _keyPair;

  KeyPair? get keyPair => _keyPair;
  set setKeyPair(KeyPair keyPair) => _keyPair = keyPair;

Future<void> generate(String bits) async {
    var keyPair = await RSA.generate(int.parse(bits));
    _keyPair = keyPair;
    notifyListeners();
  }
}

And this is the error I am getting:

Error Invalid argument(s): Failed to load dynamic library 'librsa_bridge.dylib': dlopen(librsa_bridge.dylib, 0x0001): tried: 'librsa_bridge.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OSlibrsa_bridge.dylib' (no such file), '/opt/homebrew/Caskroom/flutter/3.7.3/flutter/bin/cache/artifacts/engine/darwin-x64/./librsa_bridge.dylib' (no such file), '/opt/homebrew/Caskroom/flutter/3.7.3/flutter/bin/cache/artifacts/engine/darwin-x64/../../../librsa_bridge.dylib' (no such file), '/opt/homebrew/Caskroom/flutter/3.7.3/flutter/bin/cache/artifacts/engine/darwin-x64/Frameworks/librsa_bridge.dylib' (no such file), '/opt/homebrew/Caskroom/flutter/3.7.3/flutter/bin/cache/artifacts/engine/darwin-x64/./librsa_bridge.dylib' (no such file), '/opt/homebrew/Caskroom/flutter/3.7.3/flutter/bin/cache/artifacts/engine/darwin-x64/../../../librsa_bridge.dylib' (no such file), '/opt/homebrew/Caskroom/flutter/3.7.3/flutter/bin/cache/artifacts/engine/darwin-x64/Frameworks/librsa_bridge.dylib' (no such file), '/usr/lib/librsa_bridge.dylib' (no such file, not in dyld cache), 'librsa_bridge.dylib' (no such file), '/usr/lib/librsa_bridge.dylib' (no such file, not in dyld cache)
Stack trace #0      _open (dart:ffi-patch/ffi_dynamic_library_patch.dart:11:43)
#1      new DynamicLibrary.open (dart:ffi-patch/ffi_dynamic_library_patch.dart:22:12)
#2      Binding.openLib (package:fast_rsa/bridge/binding.dart:117:33)
#3      new Binding._internal (package:fast_rsa/bridge/binding.dart:26:16)
#4      Binding._singleton (package:fast_rsa/bridge/binding.dart:17:45)
#5      Binding._singleton (package:fast_rsa/bridge/binding.dart)
#6      new Binding (package:fast_rsa/bridge/binding.dart:22:12)
#7      RSA.bindingEnabled (package:fast_rsa/fast_rsa.dart:40:32)
#8      RSA.bindingEnabled (package:fast_rsa/fast_rsa.dart)
#9      RSA._call (package:fast_rsa/fast_rsa.dart:43:9)
#10     RSA._keyPairResponse (package:fast_rsa/fast_rsa.dart:79:22)
#11     RSA.generate (package:fast_rsa/fast_rsa.dart:437:18)
#12     main.<anonymous closure>.<anonymous closure>.<anonymous closure> (file:///Users/enrico/Developer/flutter/labsec-desafio/test/rsa_keys.test.dart:33:39)
#13     Mock.noSuchMethod (package:mockito/src/mock.dart:185:45)
#14     MockRSAKeysProvider.generate (file:///Users/enrico/Developer/flutter/labsec-desafio/test/rsa_keys.test.mocks.dart:75:53)
#15     main.<anonymous closure>.<anonymous closure> (file:///Users/enrico/Developer/flutter/labsec-desafio/test/rsa_keys.test.dart:37:23)
#16     Declarer.test.<anonymous closure>.<anonymous closure> (package:test_api/src/backend/declarer.dart:215:19)
<asynchronous suspension>
#17     StackZoneSpecification._registerUnaryCallback.<anonymous closure> (package:stack_trace/src/stack_zone_specification.dart:124:15)
<asynchronous suspension>

Running with Flutter 3.7.3, fast_rsa 3.5.3, mockito 5.3.2, test 1.22.0

Execution failed for task ':fast_rsa:bundleDebugAar'.

Hi.
I have a problem with installing.
Can you help ?

  • What went wrong:
    Execution failed for task ':fast_rsa:bundleDebugAar'.

Direct local .aar file dependencies are not supported when building an AAR. The resulting AAR would be broken because the classes and Android resources from any local .aar file dependencies would not be packaged in the resulting AAR. Previous versions of the Android Gradle Plugin produce broken AARs in this case too (despite not throwing this error). The following direct local .aar file dependencies of the :fast_rsa project caused this error: F:\src\flutter.pub-cache\hosted\pub.dartlang.org\fast_rsa-1.1.4\android\libs\rsa.aar

Expected format for private/public key?

In RSA.decryptOAEP and encryptOAEP, the key type is just String. But what is the expected format for those keys, or are there multiple options?

Context: I do have a private key created with a different library for tests, that is available to me as a single-line pem string, with begin-end block as in PKCS#8. I now see no way to use that key with fast_rsa without additional helpers, and do wonder if that is correct. As a test, I already used the rsaKeyHelper of rsa_encrypt to convert the key to PKCS#1, after noticing that is the format in which RSA.generateKey will present it. But this only produced an error when giving that result to decryptOAEP (an error I'm happy to share in a separate issue if this route should have worked).

Add support for importing RSA keys in JWK format

@jerson Any suggestions on how to get from a JWK format key file (as described here) to the PKCS12 format private key you're using for the PSS signer function? I'm working on an app that needs RSA-PSS signatures and manages private keys using JWK format keys so I had to write native code for the signature section. I'd love to use your library to do the signatures and get rid of my Android specific implementation.

Performance issue in profile mode

Hi, this is just a heads up. When running Fast RSA in profile mode, that is profile mode started from the IDE, the performance of RSA encrypt and decrypt operations is abysmal compared to its regular profile/release mode performance. This is not a bug in Fast RSA, but a bug in flutter/Dart and its VS Code integration, reported and confirmed in Dart-Code/Dart-Code#3838. It affects at least Android and iOS.

Just wanted to make sure you are aware of the issue and its cause before running into it, if you are not aware of it already (and ofc feel free to close this issue).

module 'fast_rsa' not found @import fast_rsa; on Mac with M1 chip

Hi!

I can't build iOS project on Mac with M1 chip - GeneratedPluginRegistrant.m:24:9: fatal error: module 'fast_rsa' not found @import fast_rsa;

On the previous laptop with Intel Chip everything was ok.

Commenting fast_rsa plugin resolves the issue... But I need this plugin to use :)

If any info should be provided - please let me know

How can we know the length of the key?

Great flutter RSA library! I have a question may be stupid... When we encrypt or decrypt a file lang than the key size, how can we know the length(128Bytes or 256Bytes) of the private key or public key? I didn't find this api in the library...

Cannot use plugin in a project using Gradle 8 due to namespace

The main error is this:

Incorrect package="dev.jerson.fast_rsa" found in source AndroidManifest.xml: /home/alex/.pub-cache/hosted/pub.dev/fast_rsa-3.6.1/android/src/main/AndroidManifest.xml.
Setting the namespace via the package attribute in the source AndroidManifest.xml is no longer supported.
Recommendation: remove package="dev.jerson.fast_rsa" from the source AndroidManifest.xml: /home/alex/.pub-cache/hosted/pub.dev/fast_rsa-3.6.1/android/src/main/AndroidManifest.xml.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':fast_rsa:processDebugManifest'.
> A failure occurred while executing com.android.build.gradle.tasks.ProcessLibraryManifest$ProcessLibWorkAction
   > Incorrect package="dev.jerson.fast_rsa" found in source AndroidManifest.xml: /home/alex/.pub-cache/hosted/pub.dev/fast_rsa-3.6.1/android/src/main/AndroidManifest.xml.
     Setting the namespace via the package attribute in the source AndroidManifest.xml is no longer supported.
     Recommendation: remove package="dev.jerson.fast_rsa" from the source AndroidManifest.xml: /home/alex/.pub-cache/hosted/pub.dev/fast_rsa-3.6.1/android/src/main/AndroidManifest.xml.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 2s
Error: Gradle task assembleProdDebug failed with exit code 1

The solution would seem to be to add namespace to build.gradle's android section as seen here and removing it from AndroidManifest.

[iOS] .RSA.generate Not working when published on TestFlight

Hi

I've been using this package for a month now and had no issue with it but yesterday when I pushed my app on Testflight, the app was working as expected,

I get this error: 'dart.core_ArgumentError_toString (kind RegularFunction)' is accessed through Dart C API without being marked as an entry point; its tree-shaken signature cannot be verified. WARNING: See https://github.com/dart-lang/sdk/blob/master/runtime/docs/compiler/aot/entry_point_pragma.md

After multiple research, I found out that it happens when calling RSA.generate(2048);

I was able to reproduce this error when debugging in profile mode

Do you have an idea on how to fix this ?

Execution failed for task ':fast_rsa:compileReleaseKotlin'.

My CI suddenly started to fail with this message: Execution failed for task ':fast_rsa:compileReleaseKotlin' when building for Android. (flutter build apk)
It's weird because I can't reproduce it locally on my machine.
I have:
flutter: 2.8.1
dart: ">=2.15.0 <3.0.0"
fast_rsa: ^3.2.0

worker issue after flutter web build

build/web/assets/packages/fast_rsa/web/assets/worker.js

worker.js:55 Uncaught (in promise) TypeError: Failed to execute 'compile' on 'WebAssembly': Incorrect response MIME type. Expected 'application/wasm'.
Screenshot 2021-09-14 at 14 06 06

Error in Flutter Web, Asset Problem

I'm getting an error while using FAST_RSA with Flutter Web. In the Android version works normally. I checked the Console for this error. I was trying using in Debug mode with Chrome.
625a001a-3c08-4fdc-9de7-5a996dae8bab
r.

PublicKey is Empty

I'm using the method RSA.generate and the result keypair is empty in some devices.

This is my code:

var result = await RSA.generate(2048);
result.publicKey; //This is empty

Thanks you!

Support DecodeChain PKCS12

Hello,
I have a small problem. I have a PCSK12 file that has multiple certificates. Would it be possible to add something like DecodeChain SSLMate/go-pkcs12#8 to your solution?"

Password: Heslo123
MIISMQIBAzCCEeoGCSqGSIb3DQEHAaCCEdsEghHXMIIR0zCCBX8GCSqGSIb3DQEHAaCCBXAEggVsMIIFaDCCBWQGCyqGSIb3DQEMCgECoIIE+zCCBPcwKQYKKoZIhvcNAQwBAzAbBBSq+lkCs6/Xu72sEtnZERldPwcdkwIDAMNQBIIEyEVs8aYSOYgKNnSrZgkwNOZyhV1syqhy9g0gRgKCvAPytqxZkO4ES87b2lHcO8ZQ3NzsP4IzbfH6PyCcaXU2mJ0bU4e9SszQJTY7X9vDYldzojYiRAw3lTPuUPs6MSnUikqKgTfvUs7FCewIKKUDoYxtudbqLByhh0g+3of1/JhB7p2i1zFAAaTE9Hb3lnoU3sR7eyYCVBcUWGnSohscXMF7znkfnIYKve42qnCfwarP621iizLUpJkuvl24gowdWx1GDoRnTz0lq5g/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5+j11xrcvHFeN8COXjh/6//KoUOFTwnGkMBdVB8GoE/fsBfrPwdy28RL/UewE+Zz18hzFj+JxKgYuqd0SqLga/JUA78mCJFPfqnwq1cMfY/cy7S6mCotuaVsIhbv435En/kMfuyEcZUKjrr5J3Otq3TFLqP1vMrREuPHL14g1GKkwjLZDGvDnxFSsJ5nzsm3c3pQ8rPYo4kko3oC436x9qAgwYo/NrrzTi4E/it/r4jkXitIVtgt5zlnxSYytp/SCa4vaQ/MO4RnCYUUfyRXzEHhUzA+MCEwCQYFKw4DAhoFAAQUHZVNSfHQECJzZ3xtfiWvT70lOMgEFAA1JTt3mzVNvqsfQHJS0tzKdDF2AgMBhqA=

Decrypting binary inputs

The problem appeared when trying to encrypt the random []byte array in Golang and decrypt it in dart/flutter.

bin := make([]byte, 32)
rand.Read(bin)
cipherText,_ :=rsa.EncryptOAEP(sha256.New(), rand.Reader, publicKey, bin, []byte{})
base64Text := base64.StdEncoding.EncodeToString(cipherText)
fmr.Println("cipherText :",base64Text)

trying to decrypt the result of this code snippet in dart/flutter may lead to an exception.

It only occurs for binary inputs and it was totally fine with text inputs.
I have no idea where the root of the problem is but it may be related to some low-level layers.

As a workaround, I just wrap binary inputs in the base64 string, but in some cases, this problem may lead to some unknown behaviors.

clang: error: no such file or directory: .../ios/.symlinks/plugins/fast_rsa/iOS/librsa_bridge.a

Hi,

I just updated from version 3.0.0 to version 3.0.2 and when I try to run my app it fails

`Ld /Users/zhack013/Library/Developer/Xcode/DerivedData/Runner-drdfnjevxzlztjhfrpamxswjnzqu/Build/Products/Debug-iphoneos/Runner.app/Runner normal (in target 'Runner' from project 'Runner')
cd /Users/zhack013/Library/Mobile\ Documents/com~apple~CloudDocs/Workspace/Perso/Missions/KISAPP/Code/kisapp/ios
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -target arm64-apple-ios9.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.5.sdk -L/Users/zhack013/Library/Developer/Xcode/DerivedData/Runner-drdfnjevxzlztjhfrpamxswjnzqu/Build/Products/Debug-iphoneos -L/Users/zhack013/Library/Developer/Xcode/DerivedData/Runner-drdfnjevxzlztjhfrpamxswjnzqu/Build/Products/Debug-iphoneos/device_info -L/Users/zhack013/Library/Developer/Xcode/DerivedData/Runner-drdfnjevxzlztjhfrpamxswjnzqu/Build/Products/Debug-iphoneos/device_info_plus -L/Users/zhack013/Library/Developer/Xcode/DerivedData/Runner-drdfnjevxzlztjhfrpamxswjnzqu/Build/Products/Debug-iphoneos/fast_rsa -L/Users/zhack013/Library/Developer/Xcode/DerivedData/Runner-drdfnjevxzlztjhfrpamxswjnzqu/Build/Products/Debug-iphoneos/flutter_contacts -L/Users/zhack013/Library/Developer/Xcode/DerivedData/Runner-drdfnjevxzlztjhfrpamxswjnzqu/Build/Products/Debug-iphoneos/flutter_keychain -L/Users/zhack013/Library/Developer/Xcode/DerivedData/Runner-drdfnjevxzlztjhfrpamxswjnzqu/Build/Products/Debug-iphoneos/flutter_secure_storage -L/Users/zhack013/Library/Developer/Xcode/DerivedData/Runner-drdfnjevxzlztjhfrpamxswjnzqu/Build/Products/Debug-iphoneos/image_picker -L/Users/zhack013/Library/Developer/Xcode/DerivedData/Runner-drdfnjevxzlztjhfrpamxswjnzqu/Build/Products/Debug-iphoneos/onesignal_flutter -L/Users/zhack013/Library/Developer/Xcode/DerivedData/Runner-drdfnjevxzlztjhfrpamxswjnzqu/Build/Products/Debug-iphoneos/path_provider -L/Users/zhack013/Library/Developer/Xcode/DerivedData/Runner-drdfnjevxzlztjhfrpamxswjnzqu/Build/Products/Debug-iphoneos/record -L/Users/zhack013/Library/Developer/Xcode/DerivedData/Runner-drdfnjevxzlztjhfrpamxswjnzqu/Build/Products/Debug-iphoneos/shared_preferences -L/Users/zhack013/Library/Mobile\ Documents/com~apple~CloudDocs/Workspace/Perso/Missions/KISAPP/Code/kisapp/ios/Pods/../.symlinks/plugins/fast_rsa/ios -F/Users/zhack013/Library/Developer/Xcode/DerivedData/Runner-drdfnjevxzlztjhfrpamxswjnzqu/Build/Products/Debug-iphoneos -F/Users/zhack013/Library/Mobile\ Documents/com~apple~CloudDocs/Workspace/Perso/Missions/KISAPP/Code/kisapp/ios/Pods/OneSignalXCFramework/iOS_SDK/OneSignalSDK/OneSignal_XCFramework -F/Users/zhack013/Library/Developer/Xcode/DerivedData/Runner-drdfnjevxzlztjhfrpamxswjnzqu/Build/Products/Debug-iphoneos/XCFrameworkIntermediates/OneSignal -filelist /Users/zhack013/Library/Developer/Xcode/DerivedData/Runner-drdfnjevxzlztjhfrpamxswjnzqu/Build/Intermediates.noindex/Runner.build/Debug-iphoneos/Runner.build/Objects-normal/arm64/Runner.LinkFileList -Xlinker -rpath -Xlinker /usr/lib/swift -Xlinker -rpath -Xlinker @executable_path/Frameworks -dead_strip -Xlinker -object_path_lto -Xlinker /Users/zhack013/Library/Developer/Xcode/DerivedData/Runner-drdfnjevxzlztjhfrpamxswjnzqu/Build/Intermediates.noindex/Runner.build/Debug-iphoneos/Runner.build/Objects-normal/arm64/Runner_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -fobjc-arc -fobjc-link-runtime -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos -L/usr/lib/swift -Xlinker -add_ast_path -Xlinker /Users/zhack013/Library/Developer/Xcode/DerivedData/Runner-drdfnjevxzlztjhfrpamxswjnzqu/Build/Intermediates.noindex/Runner.build/Debug-iphoneos/Runner.build/Objects-normal/arm64/Runner.swiftmodule -ObjC -ldevice_info -ldevice_info_plus -lfast_rsa -lflutter_contacts -lflutter_keychain -lflutter_secure_storage -limage_picker -lonesignal_flutter -lpath_provider -lrecord -lrsa_bridge -lshared_preferences -framework OneSignal -force_load /Users/zhack013/Library/Mobile Documents/com~apple~CloudDocs/Workspace/Perso/Missions/KISAPP/Code/kisapp/ios/.symlinks/plugins/fast_rsa/ios/librsa_bridge.a -lPods-Runner -Xlinker -no_adhoc_codesign -Xlinker -dependency_info -Xlinker /Users/zhack013/Library/Developer/Xcode/DerivedData/Runner-drdfnjevxzlztjhfrpamxswjnzqu/Build/Intermediates.noindex/Runner.build/Debug-iphoneos/Runner.build/Objects-normal/arm64/Runner_dependency_info.dat -o /Users/zhack013/Library/Developer/Xcode/DerivedData/Runner-drdfnjevxzlztjhfrpamxswjnzqu/Build/Products/Debug-iphoneos/Runner.app/Runner

clang: error: no such file or directory: 'Documents/comappleCloudDocs/Workspace/Perso/Missions/KISAPP/Code/kisapp/ios/.symlinks/plugins/fast_rsa/ios/librsa_bridge.a'
Command Ld failed with a nonzero exit code`

The thing is it says that the path is 'Documents/comappleCloudDocs/Workspace/Perso/Missions/KISAPP/Code/kisapp/ios/.symlinks/plugins/fast_rsa/ios/librsa_bridge.a' but it should be:

'/Users/zhack013/Library/Mobile Documents/comappleCloudDocs/Workspace/Perso/Missions/KISAPP/Code/kisapp/ios/.symlinks/plugins/fast_rsa/ios/librsa_bridge.a'

Because there is a space in my path it doesn't work...

Could you help me ?
And it also doesn't work on version 3.0.1

Thanks !

Public key is invalid

String encrypted = await RSA
.encryptPKCS1v15("Hello", "public key")
.catchError((e) => onError(e));
print(encrypted);


response:

invalid public key

dlopen failed: library "/data/data/myApp/lib/librsa_bridge.so" not found

Hello, I'm having trouble with using fast_rsa.

I'm testing it on Android API 31, and the code is:

void generateRSAKeyPair() async {
  var result = await RSA.generate(2048);   //here
  log(result.publicKey);
  log(result.privateKey);
}

And the error is :

I/flutter ( 9440): fallback to open DynamicLibrary on older devices
E/flutter ( 9440): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: Invalid argument(s): Failed to load dynamic library '/data/data/myApp/lib/librsa_bridge.so': dlopen failed: library "/data/data/myApp/lib/librsa_bridge.so" not found
E/flutter ( 9440): #0      _open (dart:ffi-patch/ffi_dynamic_library_patch.dart:11:55)
E/flutter ( 9440): #1      new DynamicLibrary.open (dart:ffi-patch/ffi_dynamic_library_patch.dart:20:12)
E/flutter ( 9440): #2      Binding.openLib (package:fast_rsa/bridge/binding.dart:139:33)
E/flutter ( 9440): #3      new Binding._internal (package:fast_rsa/bridge/binding.dart:25:16)
E/flutter ( 9440): #4      Binding._singleton (package:fast_rsa/bridge/binding.dart:16:45)
E/flutter ( 9440): #5      Binding._singleton (package:fast_rsa/bridge/binding.dart)
E/flutter ( 9440): #6      new Binding (package:fast_rsa/bridge/binding.dart:21:12)
E/flutter ( 9440): #7      RSA.bindingEnabled (package:fast_rsa/fast_rsa.dart:38:32)
E/flutter ( 9440): #8      RSA.bindingEnabled (package:fast_rsa/fast_rsa.dart)
E/flutter ( 9440): #9      RSA._call (package:fast_rsa/fast_rsa.dart:41:9)
E/flutter ( 9440): #10     RSA._keyPairResponse (package:fast_rsa/fast_rsa.dart:77:22)
E/flutter ( 9440): #11     RSA.generate (package:fast_rsa/fast_rsa.dart:435:18)

And the dependency:


dependencies:
  flutter:
    sdk: flutter
  http: 0.13.4
  json_annotation: ^4.4.0


  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.2
  rsa_encrypt: ^2.0.0
  path_provider: ^2.0.7
  encrypt: ^5.0.1
  fast_rsa: ^3.1.0

Can I get some help?

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.