Code Monkey home page Code Monkey logo

jerson / react-native-fast-openpgp Goto Github PK

View Code? Open in Web Editor NEW
43.0 4.0 17.0 308.69 MB

OpenPGP for react native made with golang for fast performance

Home Page: https://www.npmjs.com/package/react-native-fast-openpgp

License: MIT License

Java 3.12% Objective-C 1.01% Ruby 1.69% TypeScript 77.21% JavaScript 5.17% Shell 1.29% Makefile 0.07% CMake 0.33% C++ 4.10% Kotlin 1.20% C 3.02% Swift 0.02% Objective-C++ 1.76%
golang openpgp react-native autolink pgp openpgpjs react xcode jsi ffi

react-native-fast-openpgp's Introduction

react-native-fast-openpgp

Android iOS

Getting started

$ npm install react-native-fast-openpgp --save

JSI

If you want to use with JSI instead of NativeModules you need to set

import OpenPGP from "react-native-fast-openpgp";

OpenPGP.useJSI = true;

if you need to use generate methods it is a good idea to disable it, because for now JSI will block your UI but it is faster compared to NativeModules

Usage

Encrypt methods

import OpenPGP from "react-native-fast-openpgp";

const encrypted = await OpenPGP.encrypt(message: string, publicKey: string, signedEntity?: Entity, fileHints?: FileHints, options?: KeyOptions ): Promise<string>;
const outputFile = await OpenPGP.encryptFile(inputFile: string, outputFile: string, publicKey: string, signedEntity?: Entity, fileHints?: FileHints, options?: KeyOptions): Promise<number>;

const encryptedSymmetric = await OpenPGP.encryptSymmetric(message: string, passphrase: string, fileHints?: FileHints, options?: KeyOptions ): Promise<string>;
const outputFile = await OpenPGP.encryptSymmetricFile(inputFile: string, outputFile: string, passphrase: string, fileHints?: FileHints, options?: KeyOptions ): Promise<number> ;

Decrypt methods

import OpenPGP from "react-native-fast-openpgp";

const decrypted = await OpenPGP.decrypt(message: string, privateKey: string, passphrase: string, options?: KeyOptions ): Promise<string>;
const outputFile = await OpenPGP.decryptFile(inputFile: string, outputFile: string, privateKey: string, passphrase: string, options?: KeyOptions ): Promise<number>;

const decryptedSymmetric = await OpenPGP.decryptSymmetric(message: string, passphrase: string, options?: KeyOptions ): Promise<string>;
const outputFile = await OpenPGP.decryptSymmetricFile(inputFile: string, outputFile: string, passphrase: string, options?: KeyOptions ): Promise<number> ;

Sign and Verify methods

import OpenPGP from "react-native-fast-openpgp";

const signed = await OpenPGP.sign(message: string, privateKey: string, passphrase: string, options?: KeyOptions ): Promise<string>;
const signed = await OpenPGP.signFile(inputFile: string, privateKey: string, passphrase: string, options?: KeyOptions ): Promise<string>;

const verified = await OpenPGP.verify(signature: string, message: string, publicKey: string ): Promise<boolean>;
const verified = await OpenPGP.verifyFile(signature: string, inputFile: string,publicKey: string): Promise<boolean>;

Generate

import OpenPGP from "react-native-fast-openpgp";

const generated = await OpenPGP.generate(options: Options): Promise<KeyPair>;

Convert methods

import OpenPGP from "react-native-fast-openpgp";

const publicKey = await OpenPGP.convertPrivateKeyToPublicKey(privateKey: string): Promise<string>;

Metadata methods

import OpenPGP from "react-native-fast-openpgp";

const metadata1 = await OpenPGP.getPublicKeyMetadata(publicKey: string): Promise<PublicKeyMetadata>;
const metadata2 = await OpenPGP.getPrivateKeyMetadata(privateKey: string): Promise<PrivateKeyMetadata>;

Encrypt with multiple keys

import OpenPGP from "react-native-fast-openpgp";

const publicKeys = `-----BEGIN PGP PUBLIC KEY BLOCK-----

mQENBF0Tpe0BCADm+ja4vMKuodkQEhLm/092M/6gt4TaKwzv8QcA53/FrM3g8wab
D4m65Neoc7DBEdvzgK9IUMpwG5N0t+0pfWLhs8AZdMxE7RbP
=kbtq
-----END PGP PUBLIC KEY BLOCK-----
-----BEGIN PGP PUBLIC KEY BLOCK-----

mQENBF0Tpe0BCADm+ja4vMKuodkQEhLm/092M/6gt4TaKwzv8QcA53/FrM3g8wab
D4m65Neoc7DBEdvzgK9IUMpwG5N0t+0pfWLhs8AZdMxE7RbP
=kbtq
-----END PGP PUBLIC KEY BLOCK-----
-----BEGIN PGP PUBLIC KEY BLOCK-----

mQENBF0Tpe0BCADm+ja4vMKuodkQEhLm/092M/6gt4TaKwzv8QcA53/FrM3g8wab
D4m65Neoc7DBEdvzgK9IUMpwG5N0t+0pfWLhs8AZdMxE7RbP
=kbtq
-----END PGP PUBLIC KEY BLOCK-----`;
const encrypted = await OpenPGP.encrypt("sample text" publicKeys);

Types

import OpenPGP from "react-native-fast-openpgp";

export enum Algorithm {
  RSA = 0,
  ECDSA = 1,
  EDDSA = 2,
  ECHD = 3,
  DSA = 4,
  ELGAMAL = 5,
}

export enum Curve {
  CURVE25519 = 0,
  CURVE448 = 1,
  P256 = 2,
  P384 = 3,
  P521 = 4,
  SECP256K1 = 5,
  BRAINPOOLP256 = 6,
  BRAINPOOLP384 = 7,
  BRAINPOOLP512 = 8,
}

export enum Hash {
  SHA256 = 0,
  SHA224 = 1,
  SHA384 = 2,
  SHA512 = 3,
}

export enum Compression {
  NONE = 0,
  ZLIB = 1,
  ZIP = 2,
}

export enum Cipher {
  AES128 = 0,
  AES192 = 1,
  AES256 = 2,
  DES = 3,
  CAST5 = 4,
}

export interface KeyOptions {
    /**
     * The public key algorithm to use - will always create a signing primary
     * key and encryption subkey.
     * @default RSA
     */
    algorithm?: Algorithm;

    /**
     * Curve configures the desired packet.Curve if the Algorithm is PubKeyAlgoECDSA,
     * PubKeyAlgoEdDSA, or PubKeyAlgoECDH. If empty Curve25519 is used.
     * @default CURVE25519
     */
    curve?: Curve;

    /**
     * RSABits is the number of bits in new RSA keys made with NewEntity.
     * If zero, then 2048 bit keys are created.
     * @default 2048
     */
    rsaBits?: number;

    /**
     * Cipher is the cipher to be used.
     * If zero, AES-128 is used.
     * @default AES128
     */
    cipher?: Cipher;

    /**
     * Compression is the compression algorithm to be
     * applied to the plaintext before encryption. If zero, no
     * compression is done.
     * @default none
     */
    compression?: Compression;

    /**
     * Hash is the default hash function to be used.
     * If zero, SHA-256 is used.
     * @default SHA256
     */
    hash?: Hash;

    /**
     * CompressionLevel is the compression level to use. It must be set to
     * between -1 and 9, with -1 causing the compressor to use the
     * default compression level, 0 causing the compressor to use
     * no compression and 1 to 9 representing increasing (better,
     * slower) compression levels. If Level is less than -1 or
     * more then 9, a non-nil error will be returned during
     * encryption. See the constants above for convenient common
     * settings for Level.
     * @default 0
     */
    compressionLevel?: number;
}

export interface Options {
    comment?: string;
    email?: string;
    name?: string;
    passphrase?: string;
    keyOptions?: KeyOptions;
}

export interface KeyPair {
    publicKey: string;
    privateKey: string;
}

export interface PublicKeyMetadata {
    keyID: string;
    keyIDShort: string;
    creationTime: string;
    fingerprint: string;
    keyIDNumeric: string;
    isSubKey: boolean;
}
export interface PrivateKeyMetadata {
    keyID: string;
    keyIDShort: string;
    creationTime: string;
    fingerprint: string;
    keyIDNumeric: string;
    isSubKey: boolean;
    encrypted: boolean;
}

/**
 * An Entity represents the components of an OpenPGP key: a primary public key
 * (which must be a signing key), one or more identities claimed by that key,
 * and zero or more subkeys, which may be encryption keys.
 */
export interface Entity {
    publicKey: string;
    privateKey: string;
    passphrase?: string;
}

export interface FileHints {
    /**
     * IsBinary can be set to hint that the contents are binary data.
     */
    isBinary?: boolean;
    /**
     * FileName hints at the name of the file that should be written. It's
     * truncated to 255 bytes if longer. It may be empty to suggest that the
     * file should not be written to disk. It may be equal to "_CONSOLE" to
     * suggest the data should not be written to disk.
     */
    fileName?: string;
    /**
     * ModTime format allowed: RFC3339, contains the modification time of the file, or the zero time if not applicable.
     */
    modTime?: string;
}

Native Code

the native library is made in Golang for faster performance

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

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT

react-native-fast-openpgp's People

Contributors

jdmunro avatar jerson avatar jerson-av 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

Watchers

 avatar  avatar  avatar  avatar

react-native-fast-openpgp's Issues

How can I upgrade openpgp-mobile version?

Hi,
I have problem using encrypt and get openpgp: invalid argument: cannot encrypt because no candidate hash functions are compiled in. (Wanted RIPEMD160 in this case.), which is similar to this issue

I think upgrade openpgp-mobile to latest version may solve this issue but the upgrade script is not working for me, is there some other way to upgrade it?

Thank!

Linking fails: Windows

When i try to install openPGP in a regular CMD i get an error, so I had to switch to git bash on windows to install it. After that the npm install was successful.

Now i am trying to link the package with calling react-native link react-native-fast-openpgp but i get an error on every terminal (Powershell/Webstorm IDE/Git Bash/CMD) no matter if it's called as administrator or not, which says:

warn Calling react-native link [packageName] is deprecated in favor of autolinking. It will be removed in the next major release.
Autolinking documentation: https://github.com/react-native-community/cli/blob/master/docs/autolinking.md
(node:43868) Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
error EPERM: operation not permitted, scandir 'D:/react-native/CalcPro/node_modules/react-native-fast-openpgp/ios/Openpgp.framework/Headers'. Run CLI with --verbose flag for more details.
Error: EPERM: operation not permitted, scandir 'D:/react-native/CalcPro/node_modules/react-native-fast-openpgp/ios/Openpgp.framework/Headers'
    at Object.readdirSync (node:fs:1072:3)
    at GlobSync._readdir (D:\react-native\CalcPro\node_modules\glob\sync.js:288:41)
    at GlobSync._readdirInGlobStar (D:\react-native\CalcPro\node_modules\glob\sync.js:267:20)
    at GlobSync._readdir (D:\react-native\CalcPro\node_modules\glob\sync.js:276:17)
    at GlobSync._processReaddir (D:\GitProjects\react-native\CalcPro\node_modules\glob\sync.js:137:22)
    at GlobSync._process (D:\react-native\CalcPro\node_modules\glob\sync.js:132:10)
    at GlobSync._processGlobStar (D:\GitProjects\react-native\CalcPro\node_modules\glob\sync.js:380:10)
    at GlobSync._process (D:\react-native\CalcPro\node_modules\glob\sync.js:130:10)
    at GlobSync._processGlobStar (D:\GitProjects\react-native\CalcPro\node_modules\glob\sync.js:383:10)
    at GlobSync._process (D:\react-native\CalcPro\node_modules\glob\sync.js:130:10)

Error: boolResponse: signature error: openpgp: unsupported feature: unknown critical signature subpacket type 33

I encountered an error on iOS (at least 14.5)

I am trying to verify a signature of following message (IBAN is a fake number I got from here )

{"id":"sepa-IE29AIBK93115212345678","type":"sepa","iban":"IE29 AIBK 9311 5212 3456 78","beneficiary":"Czino"}

Signature is the following

-----BEGIN PGP SIGNATURE-----
Version: openpgp-mobile

wsBzBAABCAAnBQJiM0WyCZDC169C4FaYTRahBMJzmMRBrEtlBEgCgMLXr0LgVphN
AAAlzQf+IK9uvxurJIa6ABf4hQn9Li48+TiERsFq60fTJw+f5kopIHGGwAhr4OKb
GoBaCW/9WU1g22GSphysKgEnPgvjsM/8WfkY0ZfE3UrcaSoj3TlwLfrwCNWcFxfb
tNN1J88Q58U9LRksetnjzzzbKy6O/3Cz0BF7MT2f0YKhT8jCXg1e0/ngMqZOJMJc
PN8GYXFW093ijMZt5G5rMSTTl3JMXA9eHFSK7Nl2kmQIp2M1QKL8EOO8OWQfyRVs
jsocjb/ch1E++LEaNaTybXT56aCd/VSFOyjGukJMvO5KEvGFIhwVRtJN0yeQR527
LEop4jqbAPz98qnLwSw7csLKWS84Kw==
=x8ST
-----END PGP SIGNATURE-----

And the corresponding public key

-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: openpgp-mobile

xsBNBGIyIM8BCAC/FTDaVmJ1kvkEF7Zv0kbQNgYmNMux0aGQMwA9fOA1Cvp/HPmL
lD3Yuy2FQt3zMPZS5nimCWprs5HeuTONf2BQApFBtXrScwDnWvwAIP6Ldbf6XtH6
Fcxx5z4oROtgyKy11McS6T50UD9Ebp7wh/KR7c3cloxH54ADefYU5McWX0+ppCpy
fZh+VIxvNBGALe1jqmQU/3TyCZKBAJ8Z2TuQqfZ+eMK7GvGJoll0DERfVbvPh4vj
9SJ0wmRdrfD50s+a1v5s59/FHvSadk7Zun0G8G9tteTTTx+ghfOSR6Bhpbmsirr/
AuvI0u8sT+tN/FQwJUBj8BT8EDWeU7WvvIVVABEBAAHNAMLAaAQTAQgAHAUCYjIg
zwkQwtevQuBWmE0CGwMCGQECCwcCFQgAAOipCAB8x52lwTA6f0FOgoIf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IhFhnK3BFX7VZaCs3Q==
=/EpH
-----END PGP PUBLIC KEY BLOCK-----

When verifying the signature in react, following error is thrown:

Error: boolResponse: signature error: openpgp: unsupported feature: unknown critical signature subpacket type 33
To make sure the signature itself is indeed correct, I imported the pubKey to my gpg keychain and verified the signature via gpg --verify which yields a good result

In react, I use the following to sign and verify:
const signature = await OpenPGP.sign(message, publicKey, privateKey, '')

and

await OpenPGP.verify(signature, message, publicKey)

$ gpg --verify message.txt.asc 
gpg: assuming signed data in 'message.txt'
gpg: Signature made Thu 17 Mar 15:29:06 2022 CET
gpg:                using RSA key C27398C441AC4B6504480280C2D7AF42E056984D
gpg: Good signature from "" [unknown]
gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.
Primary key fingerprint: C273 98C4 41AC 4B65 0448  0280 C2D7 AF42 E056 984D

Can't install library

Hello,

I have a problem, install the library with Node or Yarn.

With node i am getting this error :

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] postinstall: cd ios/native && unzip -o Openpgp.framework.zip
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

With yarn:

'unzip' is not recognized as an internal or external command,
operable program or batch file.

Unable to encrypt with certain public keys

When I use the private key from the example in the source code the encryption works. I am calling
OpenPGP.encrypt(message, publicKey)
and the aforementioned public key is

`-----BEGIN PGP PUBLIC KEY BLOCK-----

mQENBF0Tpe0BCADm+ja4vMKuodkQEhLm/092M/6gt4TaKwzv8QcA53/FrM3g8wab
oksgIN1T+CscKXOY9GeJ530sBZgu9kTsMeQW3Uf76smo2CV1W7kSTMU+XE5ExGET
+LhkKeHpXoLfZNegKuzH1Qo7DGDOByVrnijbZIukonGwvC/MTduxb69ub+YRhWJc
fCjpMhm4WsC4h0Oz3ir5kx6NsN7XGVT5ghR9OEV6jlFmJ1nYYQxMlBGiATN5f2VR
Y/T9QBLOEsLNvK4OqviLVvgPTQZ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received this error from
StringResponse.getRootAsStringResponse(result);
[Error: Error: stringResponse: publicKey error: openpgp: unsupported feature: public key type: 22]

Any assistance with this would be greatly appreciated.
Thanks in advanced

App crashes on start after installing

I have followed the instruction steps as mentioned in Readme. My app is crashing as soon as I make the build with the following error:

A/libc: Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 15162 (create_react_co), pid 14394

App Environment:

react-native: 0.59.10
react: 16.6.3
react-native-fast-openpgp: 0.4.4
Platform: Android (Emulator Pixel 2)

Android build crashes

Hi,

after adding react-native-fast-opengpg when i try to run npx react-native run-android the build fails with:

Execution failed for task ':react-native-fast-openpgp:generateJsonModelDebug'.
> java.lang.NullPointerException (no error message)

I already tried to run the build:

  • with and without hermes enabled,
  • with java 8 and java 11

My Env is as follows:

System:
    OS: macOS 12.0.1
    CPU: (10) arm64 Apple M1 Max
  Binaries:
    Node: 17.2.0 - /opt/homebrew/bin/node
    Yarn: 1.22.17 - /opt/homebrew/bin/yarn
    npm: 8.1.4 - /opt/homebrew/bin/npm
    Watchman: 2021.11.15.00 - /opt/homebrew/bin/watchman
  Managers:
    CocoaPods: 1.11.2 - /opt/homebrew/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 21.0.1, iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0
    Android SDK:
      API Levels: 26, 29, 30, 31
      Build Tools: 28.0.3, 29.0.0, 29.0.2, 30.0.0, 30.0.2, 31.0.0
      System Images: android-29 | Google APIs ARM 64 v8a, android-29 | Google Play ARM 64 v8a, android-30 | ARM 64 v8a, android-30 | Google APIs ARM 64 v8a, android-30 | Google Play ARM 64 v8a, android-31 | ARM 64 v8a, android-31 | Google APIs ARM 64 v8a, android-31 | Google Play ARM 64 v8a
      Android NDK: Not Found
  IDEs:
    Android Studio: 2020.3 AI-203.7717.56.2031.7784292
    Xcode: 13.1/13A1030d - /usr/bin/xcodebuild
  Languages:
    Java: 1.8.0_312 - /Users/.jenv/shims/javac
    Python: 2.7.18 - /usr/bin/python
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.13.1 => 16.13.1
    react-native: 0.63.4 => 0.63.4
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

If someone could point me in the right direction on how to fix this, i would be more than thankful (:

App crashes as soon as app starts on Android

The problem is that It does not always happen.

Env:

React Native: 0.65.1
Device: Pixel 4 XL
OS: Android 12

Error log:

12-27 05:09:39.016: V/react-native-fast-openpgp(23747): Initializing
12-27 05:09:39.016: V/react-native-fast-openpgp(23747): --------- beginning of crash
Build fingerprint: 'google/redfin/redfin:11/RQ3A.211001.001/7641976:user/release-keys'
Revision: 'MP1.0'
ABI: 'arm64'
Timestamp: 2021-12-27 05:09:39-0800
pid: 23747, tid: 24007, name: mqt_native_modu  >>> com.oursong.app <<<
uid: 10277
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0xfffe006ce0a4ca68
    x0  0000006cab092a10  x1  0000006ddb9213d0  x2  0000006cab092908  x3  0000000000000080
    x4  0000000000000010  x5  0000006ca96b7960  x6  636e79536c6c6163  x7  636e79536c6c6163
    x8  0000006cd9bf2b30  x9  0000006cab092af0  x10 0000000000001f44  x11 5386000000080107
    x12 0000000082bc174d  x13 5386000000080107  x14 0000006cab092738  x15 ffffffffffffffff
    x16 0000006cdfd3b2f8  x17 0000006ffc83dab8  x18 0000006caa2ee000  x19 b400006dcb6e2c78
    x20 fffe006ce0a4ca48  x21 0000006cab095000  x22 0000006cab095000  x23 b400006edb72d648
    x24 0000006d4f6e27c8  x25 0000006cab095000  x26 000000000000000b  x27 0000000000000003
    x28 0000000000000002  x29 fffe006ce0a4caa8
    lr  0000006cd9b6f67c  sp  0000006cab092aa0  pc  0000006cd9b6f694  pst 0000000060001000
backtrace:
      #00 pc 000000000004d694  /data/app/~~sFdTHGN4xt1uX974y2K9vA==/com.oursong.app-eg0QMTBOa_riyK1vgNzZrA==/split_config.arm64_v8a.apk!libfast-openpgp.so (offset 0x66f000) (fastOpenPGP::install(facebook::jsi::Runtime&)+148) (BuildId: 77664e26cc7dd040537c07b3ffcaab5b767ebdd3)

Static library only works for i86 archs

I noticed once the library is added one can only run the app when running it with rosetta (on apple silicon machines). While this might work, it's dirty. You should compile the library (or download per target .a files). You can then package all of them in an xcframework (because x86 and x86_64 clash and you cannot directly include them) and use the vendored_frameworks capability of cocoapods to require this framework and xcode will compile per architecture.

You can see an example of how to do this (in Rust, but the concept is the same) in this post

Doesn't work with Xcode 13

When I'm trying to build the app I get this error.
Undefined symbols for architecture x86_64:
"facebook::jsi::Value::Value(facebook::jsi::Runtime&, facebook::jsi::Value const&)", referenced from:
facebook::jsi::detail::toValue(facebook::jsi::Runtime&, facebook::jsi::Value const&) in react-native-fast-openpgp.o

About LICENSE

Thank you for open sourcing great library!
Could you give me/us the license information of this project?

Thank you again!

What is the equivalent of the web function for on this library?

In one of my project I need to generate public, private key using openpgp.. the thing is it has specific format to generate keys for web. But on mobile I'm not sure how to replicate this using fast openpgp library.

Web version:

const generatedKeys = await openpgp.generateKey({
        type: 'ecc',
        curve: 'curve25519',
        userIDs: [{ alias }],
        passphrase: '',
        format: 'armored',
      });

What would be the generate function arguments to achieve this?

Unable to build for iOS on M1

Android working well, but not on iOS build on MacOS M1 chip.

ld: warning: ignoring file /<DIR>/ios/VosWrapperEx.framework/VosWrapperEx, missing required architecture x86_64 in file /<DIR>/ios/VosWrapperEx.framework/VosWrapperEx (2 slices)
ld: warning: ignoring file /<DIR>/ios/nofsdk.framework/nofsdk, missing required architecture x86_64 in file /<DIR>/ios/nofsdk.framework/nofsdk (2 slices)
Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$_NofService", referenced from:
      objc-class-ref in AppDelegate.o
  "_OBJC_CLASS_$_PublicKeySet", referenced from:
      objc-class-ref in AppDelegate.o
  "_OBJC_CLASS_$_PublicKeyComponent", referenced from:
      objc-class-ref in AppDelegate.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Never really touch iOS native library before, so don't really know what does it mean.
Any help is appreciated. Thank you!

ReferenceError: Can't find variable: BigInt

Hi there, when attempting to use either OpenPGP.encryptFile or OpenPGP.decryptFile the error ReferenceError: Can't find variable: BigInt is thrown.

Versions:

"react-native": "0.68.0",
"react-native-fast-openpgp": "2.2.3"

Hermes is not enabled.

This is happening on Android, I haven't tested iOS yet.

Generate a public key from a private key?

Some users already have a private key. Would be great to be able to generate a public key from a private key, such as "readKey" and then .toPublicKey() in this JS implementation?

https://github.com/openpgpjs/openpgpjs/blob/6c32b62ef3b36527086a2551f4bfa8437c8175e4/test/general/openpgp.js#L902

  const result: openpgp.Key = await openpgp.readKey({ armoredKey: privateKey });
  const publicKey = result.toPublic();

Could we extend the interface to be something like this?

    static async import(inputFile: string): Promise<KeyPair> {
        const builder = new flatbuffers.Builder(0);
        KeyPair.createKeyPair(builder, 0, 0);
        const result = await this.call('createKeyPair', builder.asUint8Array());
        return this._keyPairResponse(result);
    }

Error calling functions on expo

When running the "generate" function on expo, creates the error "null is not an object (evaluating 'FastOpenPGPNativeModules.call')".

Adding
OpenPGP.useJSI = true;
creates the error "global.FastOpenPGPCallPromise is not a function. (In 'global.FastOpenPGPCallPromise(name, buff)', 'global.FastOpenPGPCallPromise' is undefined)"

Expose the finger print

Be handy to have the finger print too on the Key Interface

export interface KeyPair {
    publicKey: string;
    privateKey: string;
    fingerprint: string;
}

JSI functions cannot be initialized in a threaded manner (race condition)

Hi there. I client is having an issue with this module. When he turned on the JSI flag, he started experiencing a crash on the install method. I took a look and found out the initialization of JSI functions is happening in an async method, but this is basically a race condition, so it will always have a possibility of a thread error.

sure

The only way to guarantee the will be no race conditions is to make the install function synchronous and blocking. Otherwise, whenever you try to do any operation with the jsiRuntime you might get the same thread error.

'import typeof' error when running encryption example

When trying to run the example here as a script inside of my React Native project (I just want to test the basic encryption scheme without running the React Native app first):

const message = messageToEncrypt;
const encrypted = await OpenPGP.encrypt(message, publicKey); //string, string

node ./myEncryptionFile.js

I get the following error:

import typeof AccessibilityInfo from './Libraries/Components/AccessibilityInfo/AccessibilityInfo';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at Object.compileFunction (node:vm:360:18)
    at wrapSafe (node:internal/modules/cjs/loader:1088:15)
    at Module._compile (node:internal/modules/cjs/loader:1123:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
    at Module.load (node:internal/modules/cjs/loader:1037:32)
    at Module._load (node:internal/modules/cjs/loader:878:12)
    at Module.require (node:internal/modules/cjs/loader:1061:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (C:\Users\17088\my-react-native-app\node_modules\react-native-fast-openpgp\lib\commonjs\index.js:7:20)
    at Module._compile (node:internal/modules/cjs/loader:1159:14)

Node.js v18.12.1

Looks like it's coming from the require('react-native') line. Any ideas on how to resolve so I can test the encrypton? Thanks.

problems with creating Android Release

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 A
AR. 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 :react-native-fast-openpgp project caused this error

buildscript {
ext {
buildToolsVersion = "30.0.0"
minSdkVersion = 21
compileSdkVersion = 30
targetSdkVersion = 29
supportLibVersion = "28.0.0"
ndkVersion = "20.1.5948944"
googlePlayServicesVersion = "11+"
}
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle:4.1.0")
classpath 'com.google.gms:google-services:4.3.5'
}
}

"react": "17.0.1",
"react-native": "0.63.4",

openpgp: invalid data: tag byte does not have MSB set

Hello,

I am using the latest version of the project.

Using the following code to decrypt a file locally stored:

await OpenPGP.decryptFile(file_path, file_path_decrypted, this.state.keys.private).then((content) => {
                    console.log('Decrypted file saved', file_path_decrypted);
                }).catch((error) => {
                    console.log('Decrypting file ', file_transfer.filename, ' error:', error);
                });

I get:

Decrypting file  FvH1wsSWIAYEwz1.jpeg.asc  error: Error: intResponse: openpgp: invalid data: tag byte does not have MSB set
    at Function._intResponse (index.tsx:713:13)
    at Function.decryptFile$ (index.tsx:265:17)
    at tryCatch (runtime.js:45:40)
    at Generator.invoke [as _invoke] (runtime.js:271:22)
    at prototype.<computed> [as next] (runtime.js:97:21)
    at tryCatch (runtime.js:45:40)
    at invoke (runtime.js:135:20)
    at runtime.js:145:13
    at tryCallOne (core.js:37:12)
    at core.js:123:15

TypeError: null is not an object (evaluating 'FastOpenPGPNativeModules.install')

when running:

import OpenPGP, {Curve, Hash} from 'react-native-fast-openpgp';
OpenPGP.useJSI = true;

const ephemeral_private_key = await OpenPGP.generate({
  keyOptions: {
    curve: Curve.SECP256K1,
    hash: Hash.SHA256,
  },
});

i get:

{"error": [TypeError: null is not an object (evaluating 'FastOpenPGPNativeModules.install')]}

system info:

System:
    OS: macOS 13.1
    CPU: (12) x64 Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz
    Memory: 174.49 MB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 14.21.2 - ~/.nvm/versions/node/v14.21.2/bin/node
    Yarn: 1.22.19 - ~/Projects/xxx/yyy/node_modules/.bin/yarn
    npm: 6.14.17 - ~/.nvm/versions/node/v14.21.2/bin/npm
    Watchman: 2022.10.03.00 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.11.3 - /Users/xxx/.rvm/gems/ruby-2.7.4/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 22.2, iOS 16.2, macOS 13.1, tvOS 16.1, watchOS 9.1
    Android SDK:
      Android NDK: 22.1.7171670
  IDEs:
    Android Studio: 2021.3 AI-213.7172.25.2113.9123335
    Xcode: 14.2/14C18 - /usr/bin/xcodebuild
  Languages:
    Java: javac 14 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 18.1.0 => 18.1.0 
    react-native: 0.68.0 => 0.68.0 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

multi-key encryption

Hi, thanks for the library.

Is it possible to encrypt a message with multiple public keys so that any of the private keys can decrypt it?

thanks!

Fail to decrypt on IOS: no armored data found

The Code:

        const is_encrypted =  message.content.indexOf('-----BEGIN PGP MESSAGE-----') > -1 && message.content.indexOf('-----END PGP MESSAGE-----') > -1;
        console.log('Got message:');
        console.log(message.content);

        if (is_encrypted) {
            if (!this.state.keys || !this.state.keys.private) {
                console.log('Missing private key, cannot decrypt message');
                this.saveSystemMessage(message.sender.uri, 'Cannot decrypt: no private key', 'incoming');
            } else {
                await OpenPGP.decrypt(message.content, this.state.keys.private).then((decryptedBody) => {
                    console.log('Incoming message decrypted');
                    this.handleIncomingMessage(message, decryptedBody);
                }).catch((error) => {
                    console.log('Failed to decrypt message:', error);
                    this.saveSystemMessage(message.sender.uri, 'Cannot decrypt: wrong public key', 'incoming');
                });
            }
        } else {
            //console.log('Incoming message is not encrypted');
            this.handleIncomingMessage(message, message.content);
        }

The logs:

Got message:
app.js:3718 -----BEGIN PGP MESSAGE-----

wcFMAx8ojOYXnpqaARAAoGAe5s6VGrnbFO96W9tK2eANKYITCowEbqKg8SVwLAmh
ah4Giwed0y1PBT4yWijrzWitxYqL+kv/g5DGi0/DGGf8JROvog4sZ3V8GCr4o2Vf
jrZg4FKm1FAgh4eHyzhvuxqUeFh1R7qDNH9dJy+n7KLjnM9LibiWFEjM7bRUCltQ
Y2u6Rjcmdmv5lbN2cybHAKYQXhdMB0a9yZA2pVHUKUNc235RkVIpJjFaXnyvu74D
zAh6nfRcY+JRn9vrxHgyb9H3OqTJkbPU8gkxAE51fbWZCfNq38vyL2MzIWpKDPq3
VDAKTs8TBaaqnSpqLVWDAhq1s8PK9jfR/Nt3Iql1HDceN6mlb2mMOOXx3lNYifbo
oTvUPmioylL5WXWjuHIyFAfYhBFCF+5aLYQBrQOaYUUO5wvbKJ2yuvX6vD325M01
gaE/56DkaRPEyyDP91VcgaLZfmLwj5oVhddCNwomD7aBUFnclCn7bHf84dxdZkvq
U8/f5cady0J5ADep44SQsr+T+1BP4pFU2x7shAPU7xN+BkRGDVN6Q0/l1ev4zGh8
LirPxyYUKtl0K/VdWIgUc5jIBBFTatP5PCY9IAoA1tWIODXNmAIxns4YbC2X24Il
lnp2Fyv4pyfn7NIIIBTjwXiPR8y+r3fsOHHHOA91PLwm/4O/RFlfyLkIbPapv7PS
OAGrhRokoSZ77suIRtXO11SHcyCNgBOfvjgZas2/Fs1L6c/dMH21U1PRzfHNKfEz
Bn2Ta/YgJ3tu
=ZMwW
-----END PGP MESSAGE-----

app.js:3729 Failed to decrypt message: Error: Error Domain=go Code=1 "openpgp: invalid argument: no armored data found" UserInfo={NSLocalizedDescription=openpgp: invalid argument: no armored data found}
    at Object.fn [as decrypt] (NativeModules.js:99)
    at Function.decrypt (index.js:5)
    at Sylk.incomingMessage$ (VM5 app.bundle:4469)
    at tryCatch (runtime.js:45)
    at Generator.invoke [as _invoke] (runtime.js:271)
    at Generator.prototype.<computed> [as next] (runtime.js:97)
    at tryCatch (runtime.js:45)
    at invoke (runtime.js:135)
    at runtime.js:170
    at tryCallTwo (core.js:45)

Work with node 12?

Hi!
Thank you for this library, it has been very helpful to us :)

I wanted to ask about this library working with node12; we want to upgrade our project from node10 to node12, but it seems like react-native-fast-openpgp will not work with node12, do you have any plans for upgrading? Or perhaps there's something my team and I can do to make it work for us?

Thank you for your time!

Default key options

Would you mind clarifying the default key options? It wasn't clear from the docs or from reading the code about what would be used if you don't specify the options manually.

Remove jcenter() from ./android/build.gradle

Thanks for this great library!

One problem I noticed this morning is, I can't run / build the android version, because jcenter is down, I get this error message:
Screenshot 2022-10-30 at 13 13 29

But after I remove jcenter() from ./android/build.gradle, things start working again:
https://github.com/jerson/react-native-fast-openpgp/blob/v2.5.0/android/build.gradle#L8
https://github.com/jerson/react-native-fast-openpgp/blob/v2.5.0/android/build.gradle#L75

Since jcenter is deprecated, i guess it's better not using it in this lib.
What do you think?

(btw, I was using nodejs-mobile-react-native and ran pure openpgpjs in my app. But this solution made my app's bundle very big, 80+MB. With your lib, my app's size decreases to 20+MB. And it's easier to use and faster. So thanks again!)

Enhance getPublicKeyMetadata to get information about subkeys

Hi, long time happy user here:)

i'm working on a feature where the app exchanges encrypted documents with other apps. Those apps don't always know the user identities. To identity which documents are requested, the key-id is used. but for this to work the app has to know the encryption subkey id (or id's) for a user. (subkeys are optional but often used)

until now i used openpgp.js to inspect keys, but i want of get rid of the dependency because it's a headache:)

would it be possible to enhance getPublicKeyMetadata to also return a list of subkeys and theirs id's with the metadata?

Request: add a method for encrypting files/bytes

Would there be any interest in adding a method to allow encrypting files on the disk?

Use case: I would like to encrypt some images on the disk - for performance reasons it doesn't make sense to fetch the images across the bridge as base64, encrypt, then write to disk across the bridge again.

Something like this:

await OpenPGP.encryptFile(inputFilePath, outputFilePath, publicKey)

Benefits of this approach: allows much higher performance of encrypting files by avoiding unnecessary encoding conversions and sending back and forth over the React Native bridge.

Cannot use encrypt

Hello !
First of all, thank you for creating this package !

I tried to create a new project with react-native-fast-openpgp, but I got an error when I use encrypt

Error: Error Domain=go Code=1 "openpgp: invalid argument: cannot encrypt because no candidate hash functions are compiled in. (Wanted RIPEMD160 in this case.)" UserInfo={NSLocalizedDescription=openpgp: invalid argument: cannot encrypt because no candidate hash functions are compiled in. (Wanted RIPEMD160 in this case.)}

I checked the github of Golang
https://github.com/golang/crypto/blob/173ce04bfaf66c7bb0fa9d5c0bfd93e773909dbd/openpgp/s2k/s2k.go#L226
Not sure if the problem is from here.

and I tried to execute upgrade_lib_bridge.sh but it failed.
It seems that we have to separate
wget -c "$FILE_URL" -O - | tar --strip-components=1 -xz -C "$OUTPUT_DIR" "$OUTPUT_SUB_DIR"
into two command lines

Just noticed some error, hope it might be helpful :)
Anyway, thanks for your contribution !

Build failed on iOS:Undefined symbols for architecture x86_64

I cannot build on ios platform. I got this error. It's worked on android.

Undefined symbols for architecture x86_64:
"OBJC_CLASS$_RCTAppDelegate", referenced from:
OBJC_CLASS$_AppDelegate in AppDelegate.o
"OBJC_CLASS$_RCTBundleURLProvider", referenced from:
objc-class-ref in AppDelegate.o
"OBJC_METACLASS$_RCTAppDelegate", referenced from:
OBJC_METACLASS$_AppDelegate in AppDelegate.o
"_RCTIsMainQueue", referenced from:
-[FastOpenpgp setBridge:] in libreact-native-fast-openpgp.a(FastOpenpgp.o)
"_RCTRegisterModule", referenced from:
+[FastOpenpgp load] in libreact-native-fast-openpgp.a(FastOpenpgp.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

System:
OS: macOS 14.1.1
CPU: (8) arm64 Apple M1
Memory: 205.69 MB / 16.00 GB
Shell:
version: "5.9"
path: /bin/zsh
Binaries:
Node:
version: 18.16.0
path: /usr/local/bin/node
Yarn:
version: 1.22.19
path: /usr/local/bin/yarn
npm:
version: 9.5.1
path: /usr/local/bin/npm
Watchman:
version: 2023.11.27.00
path: /opt/homebrew/bin/watchman
Managers:
CocoaPods:
version: 1.14.3
path: /opt/homebrew/bin/pod
SDKs:
iOS SDK:
Platforms:
- DriverKit 22.4
- iOS 16.4
- macOS 13.3
- tvOS 16.4
- watchOS 9.4
Android SDK: Not Found
IDEs:
Android Studio: 2020.3 AI-203.7717.56.2031.7784292
Xcode:
version: 14.3.1/14E300c
path: /usr/bin/xcodebuild
Languages:
Java:
version: 17.0.9
Ruby:
version: 2.7.4
npmPackages:
"@react-native-community/cli": Not Found
react:
installed: 18.2.0
wanted: 18.2.0
react-native:
installed: 0.72.5
wanted: 0.72.5
react-native-macos: Not Found
npmGlobalPackages:
"react-native": Not Found
Android:
hermesEnabled: true
newArchEnabled: false
iOS:
hermesEnabled: true
newArchEnabled: false

TypeError: null is not an object (evaluating 'FastOpenPGPNativeModules.call')

I am calling OpenPGP.verify in an android app and getting an error
TypeError: null is not an object (evaluating 'FastOpenPGPNativeModules.call')
What is going on here? I have imported the module:
import OpenPGP from 'react-native-fast-openpgp';
and am doing
OpenPGP.verify(s, d, k).then((value) => { console.log("OK: "); }, (reason) => { console.log("Failed: " + reason.toString())}).catch(()=> { console.log("EXCEPTION")});
}) (data);

Using another lib with golang

Hi, first of all, thx for your work, this lib is very usefull for our project, and also I took some inspiration and tried to use a similar approach for my other needs. I've used your project as base/example and follow the methods of using JSI on react native to execute some code on golang.

I made it work, however when I try to run an application that uses both my new lib and this one, it causes app crash.

What is weird:

If I run my app JSI install first, then your encrypt function, the app crashes. If I do otherwise (your module JSI installs, then mine), then it all works fine. Also if I use 'useJSI = false' flag for your app, then it also works fine(probably that because it loads your golib before mine).
I tried to investigate why it happens, and apparently it seems that only 1 'c-shared' go instance can run at same time on a single process.

Now the question, have you got any ideas how to handle that? Sure I can just merge the libs into single shared lib, but it looks like a meh solution since any other addition library that uses cgo will fail too. Thx in advance!

runtime: g 17: unexpected return pc for runtime.cgocallback called from 0x734454d7b4
2024-02-11 23:42:27.730 4723-0 Go com.fastencoderexample E stack: frame={sp:0x72ac09dfb0, fp:0x72ac09dfe0} stack=[0x72ac09c000,0x72ac09e000)
2024-02-11 23:42:27.730 4723-0 Go com.fastencoderexample E 0x00000072ac09deb0: 0x00000072ac09de65 0x0000004000002680
2024-02-11 23:42:27.730 4723-0 Go com.fastencoderexample E 0x00000072ac09dec0: 0x0000000200000003 0x0000004000002680
2024-02-11 23:42:27.730 4723-0 Go com.fastencoderexample E 0x00000072ac09ded0: 0x00000072ac09dea8 0x0000000000000000
2024-02-11 23:42:27.730 4723-0 Go com.fastencoderexample E 0x00000072ac09dee0: 0x00000072f714a6e8 0x00000072ac09df78
2024-02-11 23:42:27.730 4723-0 Go com.fastencoderexample E 0x00000072ac09def0: 0x00000072f6fb6b5c <runtime.cgocallbackg+0x000000000000001c> 0x00000072f70a73b0 <_cgoexp_5c653701e320_OpenPGPBridgeCall+0x0000000000000000>
2024-02-11 23:42:27.730 4723-0 Go com.fastencoderexample E 0x00000072ac09df00: 0x000000400004afe0 0x0000000000000000
2024-02-11 23:42:27.730 4723-0 Go com.fastencoderexample E 0x00000072ac09df10: 0x000000734454d7b4 0x0000000000000000
2024-02-11 23:42:27.730 4723-0 Go com.fastencoderexample E 0x00000072ac09df20: 0x0000000000000000 0x0000000000000000
2024-02-11 23:42:27.730 4723-0 Go com.fastencoderexample E 0x00000072ac09df30: 0x0000000000000000 0x0000000000000000
2024-02-11 23:42:27.730 4723-0 Go com.fastencoderexample E 0x00000072ac09df40: 0x0000000000000000 0x0000000000000000
2024-02-11 23:42:27.730 4723-0 Go com.fastencoderexample E 0x00000072ac09df50: 0x00000072ac09dfe0 0x0000004000002680
2024-02-11 23:42:27.730 4723-0 Go com.fastencoderexample E 0x00000072ac09df60: 0x000000400003c000 0x00000072f70a73b0 <_cgoexp_5c653701e320_OpenPGPBridgeCall+0x0000000000000000>
2024-02-11 23:42:27.730 4723-0 Go com.fastencoderexample E 0x00000072ac09df70: 0x00000072b0ef6900 0x00000072b0ef6808
2024-02-11 23:42:27.730 4723-0 Go com.fastencoderexample E 0x00000072ac09df80: 0x00000072f6fb4ea0 <runtime.cgocallback+0x00000000000000b0> 0x0000000000000000
2024-02-11 23:42:27.730 4723-0 Go com.fastencoderexample E 0x00000072ac09df90: 0x0000000000000000 0x0000000000000000
2024-02-11 23:42:27.730 4723-0 Go com.fastencoderexample E 0x00000072ac09dfa0: 0x0000000000000000 0x0000000000000000
2024-02-11 23:42:27.730 4723-0 Go com.fastencoderexample E 0x00000072ac09dfb0: <0x000000734454d7b4 0x00000072f70a73b0 <_cgoexp_5c653701e320_OpenPGPBridgeCall+0x0000000000000000>
2024-02-11 23:42:27.730 4723-0 Go com.fastencoderexample E 0x00000072ac09dfc0: 0x00000072b0ef6900 0x0000000000000000
2024-02-11 23:42:27.730 4723-0 Go com.fastencoderexample E 0x00000072ac09dfd0: 0x0000000000000000 0x0000000000000000
2024-02-11 23:42:27.730 4723-0 Go com.fastencoderexample E 0x00000072ac09dfe0: >0x0000000000000000 0x0000000000000000
2024-02-11 23:42:27.730 4723-0 Go com.fastencoderexample E 0x00000072ac09dff0: 0x0000000000000000 0x0000000000000000
2024-02-11 23:42:27.730 4723-0 Go com.fastencoderexample E fatal error: unknown caller pc

Request: More encode options

I'm using the lib with great results, thanks a lot:)

For my use case it would be great if wo could pass through compression options to the actual encrypt-function. I forked the lib, but react native modules are not my bread and butter and it would take me some time.

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.