The api 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 our build. So no action required on your part!
For the OpenPGP HTTP Key Server (HKP) client the new fetch api is used. There is a polyfill for both browsers and node.js runtimes. The node module is included as a dependency if you install via npm, but we do not include the browser polyfill in our build. So you'll need to include it in your app if you intend to use the HKP client.
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.useNative = false.
For environments that don't provide native crypto, the library falls back to asm.js implementations of AES-CFB, SHA-1, and SHA-256. We use Rusha and asmCrypto Lite (a minimal subset of asmCrypto.js built specifically for OpenPGP.js).
npm install --save openpgp
bower install --save openpgp
Or just fetch a minified build under dist.
Here are some examples of how to use the v2.x api. If you're upgrading from v1.x it might help to check out the documentation.
var openpgp = require'openpgp'; // use as ES6, CommonJS, AMD module or via window.openpgpopenpgpinitWorker path:'openpgp.worker.js' // set the relative web worker path
var options encrypted;options =data: 'Hello, World!' // input as Stringpasswords: 'secret stuff' // multiple passwords possible;openpgpencryptoptionsthenencrypted = armored; // '-----BEGIN PGP MESSAGE ... END PGP MESSAGE-----';
options =message: openpgpmessagereadArmoredencrypted // parse armored messagepassword: 'secret stuff' // decrypt with password;openpgpdecryptoptionsthen// return 'Hello, World!';
var options encrypted;var pubkey = '-----BEGIN PGP PUBLIC KEY BLOCK ... END PGP PUBLIC KEY BLOCK-----';var privkey = '-----BEGIN PGP PRIVATE KEY BLOCK ... END PGP PRIVATE KEY BLOCK-----';options =data: 0x01 0x01 0x01 // input as Uint8ArraypublicKeys: openpgpkeyreadArmoredpubkeykeys // for encryptionprivateKeys: openpgpkeyreadArmoredprivkeykeys // for signing (optional)armor: false // don't ASCII armor;openpgpencryptoptionsthenencrypted = messagepacketswrite; // get raw encrypted packets as Uint8Array;
options =message: openpgpmessagereadencrypted // parse encrypted bytespublicKeys: openpgpkeyreadArmoredpubkeykeys // for verification (optional)privateKey: openpgpkeyreadArmoredprivkeykeys0 // for decryptionformat: 'binary' // output as Uint8Array;openpgpdecryptoptionsthen// return Uint8Array([0x01, 0x01, 0x01]);
var options =userIds: name:'Jon Smith' email:'email@example.com' // multiple user IDsnumBits: 4096 // RSA key sizepassphrase: 'super long and hard to guess secret' // protects the private key;openpgpgenerateKeyoptionsthenvar privkey = keyprivateKeyArmored;var pubkey = keypublicKeyArmored;;
var hkp = '';var options =query: 'firstname.lastname@example.org';hkplookupoptionsthenvar pubkey = openpgpkeyreadArmoredkey;;
var hkp = '';var pubkey = '-----BEGIN PGP PUBLIC KEY BLOCK ... END PGP PUBLIC KEY BLOCK-----';hkpuploadpubkeythen ;
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.