Coder Social home page Coder Social logo

junghsuan / react-native-openpgp-webview Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 288 KB

A simple example to run openpgpjs using react-native-webview in react-native

JavaScript 16.55% Ruby 3.40% Starlark 1.57% Java 40.36% Makefile 4.02% C++ 18.25% Objective-C 6.31% Objective-C++ 9.55%
openpgp openpgpjs react-native react-native-webview

react-native-openpgp-webview's Introduction

react-native-openpgp-webview

This is a simple example to run openpgpjs using react-native-webview.
This is a full react-native project. You can simply clone and run on simulator or real devices.

Here we use react-native-webview to open a simple html which we load openpgpjs library by adding <script/> like this:

<html>
  <body>
    <script src="https://unpkg.com/[email protected]/dist/openpgp.min.js"></script>
    <div>hello word</div>
  </body>
</html>

Then, we can inject some js code to run openpgp by calling the method injectJavaScript().
Example javaScript code to use openpgp:

const jscode = `(async () => {
    const message = await openpgp.createMessage({
        binary: new Uint8Array([0x01, 0x01, 0x01]),
    });
    const encrypted = await openpgp.encrypt({
      message, // input as Message object
      passwords: ["secret stuff"], // multiple passwords possible
      format: "binary", // don't ASCII armor (for Uint8Array output)
    });
    console.log(encrypted); // Uint8Array
 };
 true;`;

Finally, inject this code by:

webViewRef.current.injectJavaScript(jscode);

That's it!
You can find full code in App.js

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.