Platform Support

The dist/openpgp.min.js bundle works well with recent versions of Chrome, Firefox, Safari and Edge. It also works in Node.js 8+.

The dist/compat/openpgp.min.js bundle also works with Internet Explorer 11 and old versions of Safari. Please note that this bundle overwrites the global Promise with a polyfill version even in some cases where it already exists, which may cause issues. It also adds some builtin prototype functions if they don't exist, such as Array.prototype.includes.

If you wish, you could even load one or the other depending on which browser the user is using. However, if you're using the Web Worker, keep in mind that you also need to pass { path: 'compat/openpgp.worker.min.js' } to initWorker whenever you load compat/openpgp.min.js.

Currently, Chrome, Safari and Edge have partial implementations of the
Streams specification, and Firefox
has a partial implementation behind feature flags. Chrome is the only
browser that implements TransformStreams, which we need, so we include
a polyfill for
all other browsers. Please note that in those browsers, the global
ReadableStream property gets overwritten with the polyfill version if
it exists. In some edge cases, you might need to use the native
ReadableStream (for example when using it to create a Response
object), in which case you should store a reference to it before loading
OpenPGP.js. There is also the
web-streams-adapter
library to convert back and forth between them.

Performance

Version 3.0.0 of the library introduces support for public-key cryptography using elliptic curves. We use native implementations on browsers and Node.js when available or Elliptic otherwise. Elliptic curve cryptography provides stronger security per bits of key, which allows for much faster operations. Currently the following curves are supported (* = when available):

Version 2.x of the library has been built from the ground up with Uint8Arrays. This allows for much better performance and memory usage than strings.

If the user's browser supports native WebCrypto via the window.crypto.subtle API, this will be used. Under Node.js the native crypto module is used. This can be deactivated by setting openpgp.config.use_native = false.

The library implements the IETF proposal for authenticated encryption using native AES-EAX, OCB, or GCM. This makes symmetric encryption up to 30x faster on supported platforms. Since the specification has not been finalized and other OpenPGP implementations haven't adopted it yet, the feature is currently behind a flag. Note: activating this setting can break compatibility with other OpenPGP implementations, and also with future versions of OpenPGP.js. Don't use it with messages you want to store on disk or in a database. You can enable it by setting openpgp.config.aead_protect = true.

We previously also implemented an earlier version of the draft (using GCM), which you could enable by setting openpgp.config.aead_protect = true. If you need to stay compatible with that version, you need to set openpgp.config.aead_protect_version = 0.

For environments that don't provide native crypto, the library falls back to asm.js implementations of AES, SHA-1, and SHA-256. We use Rusha and asmCrypto Lite (a minimal subset of asmCrypto.js built specifically for OpenPGP.js).

Getting started

Npm

npm install --save openpgp

Bower

Examples

Here are some examples of how to use the v2.x+ API. For more elaborate examples and working code, please check out the public API unit tests. If you're upgrading from v1.x it might help to check out the documentation.

Possible values for curve are: curve25519, ed25519, p256, p384, p521, secp256k1,
brainpoolP256r1, brainpoolP384r1, or brainpoolP512r1.
Note that options both curve25519 and ed25519 generate a primary key for signing using Ed25519
and a subkey for encryption using Curve25519.

Security Audit

To date the OpenPGP.js code base has undergone two complete security audits from Cure53. The first audit's report has been published here.

Security recommendations

It should be noted that js crypto apps deployed via regular web hosting (a.k.a. host-based security) provide users with less security than installable apps with auditable static versions. Installable apps can be deployed as a Firefox or Chrome packaged app. These apps are basically signed zip files and their runtimes typically enforce a strict Content Security Policy (CSP) to protect users against XSS. This blogpost explains the trust model of the web quite well.

It is also recommended to set a strong passphrase that protects the user's private key on disk.

Development

To create your own build of the library, just run the following command after cloning the git repo. This will download all dependencies, run the tests and create a minified bundle under dist/openpgp.min.js to use in your project:

How do I get involved?

You want to help, great! Go ahead and fork our repo, make your changes and send us a pull request.

License

GNU Lesser General Public License (3.0 or any later version). Please take a look at the LICENSE file for more information.

Resources

Below is a collection of resources, many of these were projects that were in someway a precursor to the current OpenPGP.js project. If you'd like to add your link here, please do so in a pull request or email to the list.