1
0
mirror of https://github.com/Luzifer/wasm-openssl.git synced 2024-09-18 23:42:57 +00:00
WASM wrapper around go-openssl to be used in Javascript projects
Go to file
2018-09-18 18:53:27 +02:00
example Cleanup main dir 2018-09-18 18:42:46 +02:00
vendor/github.com/Luzifer/go-openssl Convert to be auto-build compliant 2018-09-18 18:40:13 +02:00
.gitignore Cleanup main dir 2018-09-18 18:42:46 +02:00
.repo-runner.yaml Convert to be auto-build compliant 2018-09-18 18:40:13 +02:00
golang.sh Convert to be auto-build compliant 2018-09-18 18:40:13 +02:00
Gopkg.lock Convert to be auto-build compliant 2018-09-18 18:40:13 +02:00
Gopkg.toml Convert to be auto-build compliant 2018-09-18 18:40:13 +02:00
History.md prepare release v0.1.0 2018-09-18 18:53:27 +02:00
LICENSE Update META 2018-09-18 18:52:37 +02:00
main.go Convert to be auto-build compliant 2018-09-18 18:40:13 +02:00
Makefile Cleanup main dir 2018-09-18 18:42:46 +02:00
README.md Update META 2018-09-18 18:52:37 +02:00

Go Report Card

Luzifer / wasm-openssl

wasm-openssl is a WASM wrapper around go-openssl to be used in Javascript projects.

Usage

You will need to have wasm_exec.js installed in your project to load the binary:

$ curl -sSfLo wasm_exec.js "https://raw.githubusercontent.com/golang/go/go1.11/misc/wasm/wasm_exec.js"

Afterwards in your HTML you can include the wasm_exec.js and load the binary:

<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
  </head>
  <body>
    <script src="wasm_exec.js"></script>
    <script>
      function opensslLoaded() { console.log("openssl.wasm loaded") }

      const go = new Go()
      WebAssembly.instantiateStreaming(fetch("openssl.wasm"), go.importObject).then(async obj => await go.run(obj.instance))
    </script>
  </body>
</html>

Be sure to have a top-level function opensslLoaded() defined as this will be called in the initialization of the openssl.wasm. This serves as a notification you do have now access to the top-level functions encrypt and decrypt:

function decrypt(ciphertext, passphrase, callback) {}
function encrypt(plaintext, passphrase, callback) {}

The functions will not return anything in the moment as in the current state Go WASM support does not have return values. Instead the callback function you've provided will be called and always have two arguments: function callback(result, error) - The result will be the plaintext on decrypt and the ciphertext on encrypt. The error will either be null or a string containing details about the error. When an error occurred the result is null.