For server side use, install via npm:
npm install openpgp
For use in browser, install via bower:
bower install --save openpgp
Or Fetch a minified build under dist.
The library can be loaded via AMD/require.js or accessed globally via
OpenPGP.js only supports browsers that implement
window.crypto.getRandomValues. Also, if the browsers support native WebCrypto via the
window.crypto.subtle api, this will be used. Though this can be deactivated by setting
config.useWebCrypto = false. In this case the library will fall back to Web Worker operations if the
initWorker(workerPath) is set.
OpenPGP.js uses ES6 promises which are available in most modern browsers. If you need to support browsers that do not support Promises, fear not! There is a polyfill, which is included in the build step. So no action required on the developer's part for promises!
var openpgp = require'openpgp';var key = '-----BEGIN PGP PUBLIC KEY BLOCK ... END PGP PUBLIC KEY BLOCK-----';var publicKey = openpgpkeyreadArmoredkey;openpgpencryptMessagepublicKeykeys 'Hello, World!'then// successcatch// failure;
var openpgp = require'openpgp';var key = '-----BEGIN PGP PRIVATE KEY BLOCK ... END PGP PRIVATE KEY BLOCK-----';var privateKey = openpgpkeyreadArmoredkeykeys0;privateKeydecrypt'passphrase';var pgpMessage = '-----BEGIN PGP MESSAGE ... END PGP MESSAGE-----';pgpMessage = openpgpmessagereadArmoredpgpMessage;openpgpdecryptMessageprivateKey pgpMessagethen// successcatch// failure;
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.
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 minifed bundle under
dist/openpgp.min.js to use in your project:
npm install && npm test
You want to help, great! Go ahead and fork our repo, make your changes and send us a pull request.
GNU Lesser General Public License (3.0 or any later version). Please take a look at the LICENSE file for more information.
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.