Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

openpgp

Package Overview
Dependencies
Maintainers
5
Versions
179
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

openpgp - npm Package Compare versions

Comparing version 4.10.10 to 5.0.0-0

dist/lightweight/bn.interface.min.mjs

107

package.json
{
"name": "openpgp",
"description": "OpenPGP.js is a Javascript implementation of the OpenPGP protocol. This is defined in RFC 4880.",
"version": "4.10.10",
"version": "5.0.0-0",
"license": "LGPL-3.0+",

@@ -16,3 +16,9 @@ "homepage": "https://openpgpjs.org/",

],
"main": "dist/openpgp.js",
"main": "dist/node/openpgp.min.js",
"module": "dist/node/openpgp.min.mjs",
"browser": {
"./dist/node/openpgp.min.js": "./dist/openpgp.min.js",
"./dist/node/openpgp.min.mjs": "./dist/openpgp.min.mjs"
},
"types": "openpgp.d.ts",
"directories": {

@@ -22,65 +28,66 @@ "lib": "src"

"files": [
"src/",
"dist/",
"test/unittests.js",
"test/general",
"test/crypto"
"lightweight/",
"openpgp.d.ts"
],
"esm": {
"cjs": {
"dedefault": true
}
},
"scripts": {
"build": "grunt build --compat copy:openpgp_compat && grunt build --lightweight copy:openpgp_lightweight clean:js && grunt build",
"pretest": "grunt",
"test": "grunt test",
"lint": "eslint src"
"build": "rollup --config",
"build-test": "npm run build --build-only=test",
"prepare": "npm run build",
"test": "mocha --require esm --timeout 120000 test/unittests.js",
"test-type-definitions": "tsc test/typescript/definitions.ts && node test/typescript/definitions.js",
"start": "http-server",
"prebrowsertest": "npm run build-test",
"browsertest": "npm start -- -o test/unittests.html",
"browserstack": "karma start test/karma.conf.js",
"coverage": "nyc npm test",
"lint": "eslint .",
"docs": "jsdoc --configure .jsdocrc.js --destination docs --recurse README.md src",
"preversion": "rm -rf dist docs node_modules && npm install && npm test",
"version": "npm run docs && git add -A docs",
"postversion": "git push && git push --tags && npm publish"
},
"devDependencies": {
"babel-core": "^6.26.3",
"babel-plugin-syntax-async-functions": "^6.13.0",
"babel-plugin-transform-async-to-generator": "^6.24.1",
"babel-plugin-transform-regenerator": "^6.26.0",
"babel-plugin-transform-remove-strict-mode": "0.0.2",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.7.0",
"babel-preset-es2015-mod": "^6.6.0",
"babel-preset-es3": "^1.0.1",
"babelify": "^8.0.0",
"browserify-derequire": "^0.9.4",
"@mattiasbuelens/web-streams-adapter": "0.1.0-alpha.5",
"@rollup/plugin-commonjs": "^11.1.0",
"@rollup/plugin-node-resolve": "^7.1.3",
"@rollup/plugin-replace": "^2.3.2",
"@types/chai": "^4.2.14",
"asmcrypto.js": "github:openpgpjs/asmcrypto#5b994303a9d3e27e0915f72a10b6c2c51535a4dc",
"babel-eslint": "^10.1.0",
"bn.js": "^4.11.8",
"buffer": "^5.0.8",
"chai": "^4.1.2",
"chai-as-promised": "^7.1.1",
"core-js": "^2.5.3",
"elliptic": "github:openpgpjs/elliptic#ab7d8268c60b6abeb175841c578c224ac5b2d279",
"email-addresses": "3.1.0",
"eslint": "^4.17.0",
"eslint-config-airbnb": "^16.1.0",
"eslint-config-airbnb-base": "^12.1.0",
"eslint-plugin-chai-friendly": "^0.5.0",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-chai-friendly": "^0.5.0",
"grunt": "^1.1.0",
"grunt-browserify": "^5.3.0",
"grunt-contrib-clean": "~1.1.0",
"grunt-contrib-connect": "~1.0.2",
"grunt-contrib-copy": "~1.0.0",
"grunt-contrib-watch": "^1.1.0",
"grunt-header": "^1.1.0",
"grunt-jsbeautifier": "^0.2.13",
"grunt-jsdoc": "^2.2.1",
"grunt-mocha-test": "^0.13.3",
"grunt-simple-nyc": "^3.0.1",
"grunt-terser": "^0.1.0",
"grunt-text-replace": "~0.4.0",
"gruntify-eslint": "^4.0.0",
"esm": "^3.2.25",
"hash.js": "^1.1.3",
"http-server": "^0.12.3",
"jsdoc": "github:openpgpjs/jsdoc#ff7cb3929586868bf91deb78a26d7e217e051a0f",
"karma": "^6.1.0",
"karma-browserstack-launcher": "^1.6.0",
"karma-mocha": "^2.0.1",
"karma-mocha-reporter": "^2.2.5",
"mocha": "^5.0.0",
"nyc": "^14.1.1",
"pako": "github:openpgpjs/pako#f38f7368a5fa511e54b95add2f04444c3a9d803f",
"rollup": "^2.38.5",
"rollup-plugin-terser": "^5.3.0",
"seek-bzip": "github:openpgpjs/seek-bzip#4b89457f20c0e1921b4689106a31c99782c29829",
"sinon": "^4.3.0",
"text-encoding-utf-8": "^1.0.2",
"whatwg-fetch": "^2.0.3",
"@mattiasbuelens/web-streams-polyfill": "^0.3.1",
"asmcrypto.js": "github:openpgpjs/asmcrypto#475cffa5ccb2cf2556427056679414acf3610d1b",
"bn.js": "^4.11.8",
"buffer": "^5.0.8",
"elliptic": "github:openpgpjs/elliptic#ab7d8268c60b6abeb175841c578c224ac5b2d279",
"hash.js": "^1.1.3",
"pako": "^1.0.6",
"seek-bzip": "github:openpgpjs/seek-bzip#6187fc025851d35c4e104a25ea15a10b9b8d6f7d",
"tweetnacl": "github:openpgpjs/tweetnacl-js#3dae25bd3eaa77173f3405676b595721dde92eec",
"web-stream-tools": "github:openpgpjs/web-stream-tools#dc4b05e8a272b45819233f3df735423432beacfc",
"email-addresses": "3.1.0"
"typescript": "^4.1.2",
"web-stream-tools": "github:openpgpjs/web-stream-tools#5e6cb1a976d50c421091907615cf7cce77ac4f2a",
"whatwg-fetch": "^2.0.3"
},

@@ -87,0 +94,0 @@ "dependencies": {

@@ -1,7 +0,6 @@

OpenPGP.js [![Build Status](https://travis-ci.org/openpgpjs/openpgpjs.svg?branch=master)](https://travis-ci.org/openpgpjs/openpgpjs) [![BrowserStack Status](https://automate.browserstack.com/badge.svg?badge_key=eEkxVVM1TytwOGJNWEdnTjk4Y0VNUUNyR3pXcEtJUGRXOVFBRjVNT1JpUT0tLTZYUlZaMWdtQWs4Z0ROS3grRXc2bFE9PQ==--4a9cac0d6ea009d81aff66de0dbb239edd1aef3c)](https://automate.browserstack.com/public-build/eEkxVVM1TytwOGJNWEdnTjk4Y0VNUUNyR3pXcEtJUGRXOVFBRjVNT1JpUT0tLTZYUlZaMWdtQWs4Z0ROS3grRXc2bFE9PQ==--4a9cac0d6ea009d81aff66de0dbb239edd1aef3c) [![Join the chat on Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/openpgpjs/openpgpjs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
OpenPGP.js [![BrowserStack Status](https://automate.browserstack.com/badge.svg?badge_key=eEkxVVM1TytwOGJNWEdnTjk4Y0VNUUNyR3pXcEtJUGRXOVFBRjVNT1JpUT0tLTZYUlZaMWdtQWs4Z0ROS3grRXc2bFE9PQ==--4a9cac0d6ea009d81aff66de0dbb239edd1aef3c)](https://automate.browserstack.com/public-build/eEkxVVM1TytwOGJNWEdnTjk4Y0VNUUNyR3pXcEtJUGRXOVFBRjVNT1JpUT0tLTZYUlZaMWdtQWs4Z0ROS3grRXc2bFE9PQ==--4a9cac0d6ea009d81aff66de0dbb239edd1aef3c) [![Join the chat on Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/openpgpjs/openpgpjs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
==========
[OpenPGP.js](https://openpgpjs.org/) is a JavaScript implementation of the OpenPGP protocol. This is defined in [RFC 4880](https://tools.ietf.org/html/rfc4880).
[OpenPGP.js](https://openpgpjs.org/) is a JavaScript implementation of the OpenPGP protocol. It implements [RFC4880](https://tools.ietf.org/html/rfc4880) and parts of [RFC4880bis](https://tools.ietf.org/html/draft-ietf-openpgp-rfc4880bis-10).
<!-- markdown-toc start - Don't edit this section. Run M-x markdown-toc-generate-toc again -->
**Table of Contents**

@@ -13,6 +12,6 @@

- [Getting started](#getting-started)
- [Npm](#npm)
- [Bower](#bower)
- [Node.js](#nodejs)
- [Browser (webpack)](#browser-webpack)
- [Browser (plain files)](#browser-plain-files)
- [Examples](#examples)
- [Set up](#set-up)
- [Encrypt and decrypt *Uint8Array* data with a password](#encrypt-and-decrypt-uint8array-data-with-a-password)

@@ -36,14 +35,9 @@ - [Encrypt and decrypt *String* data with PGP keys](#encrypt-and-decrypt-string-data-with-pgp-keys)

- [License](#license)
- [Resources](#resources)
<!-- markdown-toc end -->
### 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/openpgp.min.js` bundle works well with recent versions of Chrome, Firefox, Safari and Edge.
* 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 built-in prototype functions if they don't exist, such as `Array.prototype.includes`.
* The `dist/node/openpgp.min.js` bundle works well in Node.js. It is used by default when you `require('openpgp')` in Node.js.
* 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

@@ -65,22 +59,25 @@ [Streams specification](https://streams.spec.whatwg.org/), and Firefox

* Version 3.0.0 of the library introduces support for public-key cryptography using [elliptic curves](https://wiki.gnupg.org/ECC). We use native implementations on browsers and Node.js when available or [Elliptic](https://github.com/indutny/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 3.0.0 of the library introduces support for public-key cryptography using [elliptic curves](https://wiki.gnupg.org/ECC). We use native implementations on browsers and Node.js when available. Elliptic curve cryptography provides stronger security per bits of key, which allows for much faster operations. Currently the following curves are supported:
| Curve | Encryption | Signature | NodeCrypto | WebCrypto | Constant-Time |
|:---------------:|:----------:|:---------:|:----------:|:---------:|:-----------------:|
| curve25519 | ECDH | N/A | No | No | Algorithmically** |
| ed25519 | N/A | EdDSA | No | No | Algorithmically** |
| p256 | ECDH | ECDSA | Yes* | Yes* | If native*** |
| p384 | ECDH | ECDSA | Yes* | Yes* | If native*** |
| p521 | ECDH | ECDSA | Yes* | Yes* | If native*** |
| brainpoolP256r1 | ECDH | ECDSA | Yes* | No | If native*** |
| brainpoolP384r1 | ECDH | ECDSA | Yes* | No | If native*** |
| brainpoolP512r1 | ECDH | ECDSA | Yes* | No | If native*** |
| secp256k1 | ECDH | ECDSA | Yes* | No | If native*** |
| Curve | Encryption | Signature | Elliptic | NodeCrypto | WebCrypto |
|:--------------- |:----------:|:---------:|:--------:|:----------:|:---------:|
| p256 | ECDH | ECDSA | Yes | Yes* | Yes* |
| p384 | ECDH | ECDSA | Yes | Yes* | Yes* |
| p521 | ECDH | ECDSA | Yes | Yes* | Yes* |
| secp256k1 | ECDH | ECDSA | Yes | Yes* | No |
| brainpoolP256r1 | ECDH | ECDSA | Yes | Yes* | No |
| brainpoolP384r1 | ECDH | ECDSA | Yes | Yes* | No |
| brainpoolP512r1 | ECDH | ECDSA | Yes | Yes* | No |
| curve25519 | ECDH | N/A | Yes | No | No |
| ed25519 | N/A | EdDSA | Yes | No | No |
\* when available
\** the curve25519 and ed25519 implementations are algorithmically constant-time, but may not be constant-time after optimizations of the JavaScript compiler
\*** these curves are only constant-time if the underlying native implementation is available and constant-time
* 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](https://caniuse.com/#feat=cryptography) via the `window.crypto.subtle` API, this will be used. Under Node.js the native [crypto module](https://nodejs.org/api/crypto.html#crypto_crypto) is used. This can be deactivated by setting `openpgp.config.use_native = false`.
* If the user's browser supports [native WebCrypto](https://caniuse.com/#feat=cryptography) via the `window.crypto.subtle` API, this will be used. Under Node.js the native [crypto module](https://nodejs.org/api/crypto.html#crypto_crypto) is used.
* The library implements the [IETF proposal](https://tools.ietf.org/html/draft-ietf-openpgp-rfc4880bis-07) 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`.
* The library implements the [IETF proposal](https://tools.ietf.org/html/draft-ietf-openpgp-rfc4880bis-10) 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.aeadProtect = true`.

@@ -90,8 +87,8 @@ You can change the AEAD mode by setting one of the following options:

```
openpgp.config.aead_mode = openpgp.enums.aead.eax // Default, native
openpgp.config.aead_mode = openpgp.enums.aead.ocb // Non-native
openpgp.config.aead_mode = openpgp.enums.aead.experimental_gcm // **Non-standard**, fastest
openpgp.config.aeadMode = openpgp.enums.aead.eax // Default, native
openpgp.config.aeadMode = openpgp.enums.aead.ocb // Non-native
openpgp.config.aeadMode = openpgp.enums.aead.experimentalGcm // **Non-standard**, fastest
```
* For environments that don't provide native crypto, the library falls back to [asm.js](https://caniuse.com/#feat=asmjs) implementations of AES, SHA-1, and SHA-256. We use [Rusha](https://github.com/srijs/rusha) and [asmCrypto Lite](https://github.com/openpgpjs/asmcrypto-lite) (a minimal subset of asmCrypto.js built specifically for OpenPGP.js).
* For environments that don't provide native crypto, the library falls back to [asm.js](https://caniuse.com/#feat=asmjs) implementations of AES, SHA-1, and SHA-256.

@@ -101,81 +98,101 @@

#### Npm
#### Node.js
npm install --save openpgp
Install OpenPGP.js using npm and save it in your dependencies:
#### Bower
```sh
npm install --save openpgp
```
bower install --save openpgp
And import it as a CommonJS module:
Or just fetch a minified build under [dist](https://github.com/openpgpjs/openpgpjs/tree/master/dist).
```js
const openpgp = require('openpgp');
```
Or as an ES6 module, from an .mjs file:
### Examples
```js
import * as openpgp from 'openpgp';
```
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](https://github.com/openpgpjs/openpgpjs/blob/master/test/general/openpgp.js). If you're upgrading from v1.x it might help to check out the [documentation](https://github.com/openpgpjs/openpgpjs#documentation).
#### Browser (webpack)
#### Set up
Install OpenPGP.js using npm and save it in your devDependencies:
##### Node.js
```sh
npm install --save-dev openpgp
```
And import it as an ES6 module:
```js
const openpgp = require('openpgp');
import * as openpgp from 'openpgp';
```
##### Browser
You can also only import the functions you need, as follows:
Copy `dist/openpgp.min.js` or `dist/compat/openpgp.min.js` (depending on the browser support you need, see [Platform Support](#platform-support)) to your project folder, and load it in a script tag:
```html
<script src="openpgp.min.js"></script>
```js
import { readMessage, decrypt } from 'openpgp';
```
If you want to use the built-in Web Worker, to offload cryptographic operations off the main thread:
Or, if you want to use the lightweight build (which is smaller, and lazily loads non-default curves on demand):
```js
await openpgp.initWorker({ path: 'openpgp.worker.js' }); // set the relative web worker path
import * as openpgp from 'openpgp/lightweight';
```
On logout, be sure to destroy the worker again, to clear private keys from memory:
To test whether the lazy loading works, try to generate a key with a non-standard curve:
```js
await openpgp.destroyWorker();
import { generateKey } from 'openpgp/lightweight';
await generateKey({ curve: 'brainpoolP512r1', userIds: [{ name: 'Test', email: 'test@test.com' }] });
```
Alternatively, you can also implement a Web Worker in your application and load OpenPGP.js from there. This can be more performant if you store or fetch keys and messages directly inside the Worker, so that they don't have to be `postMessage`d there.
For more examples of how to generate a key, see [Generate new key pair](#generate-new-key-pair). It is recommended to use `curve25519` instead of `brainpoolP512r1` by default.
If you want to use the lightweight build (which is smaller, and lazily loads non-default curves on demand), copy `dist/lightweight/openpgp.min.js` and `dist/lightweight/elliptic.min.js`, load the former in a script tag, and point `openpgp.config.indutny_elliptic_path` to the latter:
#### Browser (plain files)
Grab `openpgp.min.js` from [unpkg.com/openpgp/dist](https://unpkg.com/openpgp/dist/), and load it in a script tag:
```html
<script src="lightweight/openpgp.min.js"></script>
<script>
openpgp.config.indutny_elliptic_path = 'lightweight/elliptic.min.js';
</script>
<script src="openpgp.min.js"></script>
```
To test whether the lazy loading works, try:
Or, to load OpenPGP.js as an ES6 module, grab `openpgp.min.mjs` from [unpkg.com/openpgp/dist](https://unpkg.com/openpgp/dist/), and import it as follows:
```js
await openpgp.generateKey({ curve: 'brainpoolP512r1', userIds: [{ name: 'Test', email: 'test@test.com' }] });
```html
<script type="module">
import * as openpgp from './openpgp.min.mjs';
</script>
```
For more examples of how to generate a key, see [Generate new key pair](#generate-new-key-pair). It is recommended to use `curve25519` instead of `brainpoolP512r1` by default.
To offload cryptographic operations off the main thread, you can implement a Web Worker in your application and load OpenPGP.js from there. For an example Worker implementation, see `test/worker/worker_example.js`.
### Examples
Here are some examples of how to use OpenPGP.js v5. For more elaborate examples and working code, please check out the [public API unit tests](https://github.com/openpgpjs/openpgpjs/blob/master/test/general/openpgp.js). If you're upgrading from v4 it might help to check out the [changelog](https://github.com/openpgpjs/openpgpjs/wiki/V5-Changelog) and [documentation](https://github.com/openpgpjs/openpgpjs#documentation).
#### Encrypt and decrypt *Uint8Array* data with a password
Encryption will use the algorithm specified in config.encryption_cipher (defaults to aes256), and decryption will use the algorithm used for encryption.
Encryption will use the algorithm specified in config.encryptionCipher (defaults to aes256), and decryption will use the algorithm used for encryption.
```js
(async () => {
const { message } = await openpgp.encrypt({
message: openpgp.message.fromBinary(new Uint8Array([0x01, 0x01, 0x01])), // input as Message object
passwords: ['secret stuff'], // multiple passwords possible
armor: false // don't ASCII armor (for Uint8Array output)
const message = openpgp.Message.fromBinary(new Uint8Array([0x01, 0x01, 0x01]));
const encrypted = await openpgp.encrypt({
message, // input as Message object
passwords: ['secret stuff'], // multiple passwords possible
armor: false // don't ASCII armor (for Uint8Array output)
});
const encrypted = message.packets.write(); // get raw encrypted packets as Uint8Array
console.log(encrypted); // Uint8Array
const encryptedMessage = await openpgp.readMessage({
binaryMessage: encrypted // parse encrypted bytes
});
const { data: decrypted } = await openpgp.decrypt({
message: await openpgp.message.read(encrypted), // parse encrypted bytes
passwords: ['secret stuff'], // decrypt with password
format: 'binary' // output as Uint8Array
message: encryptedMessage,
passwords: ['secret stuff'], // decrypt with password
format: 'binary' // output as Uint8Array
});

@@ -194,4 +211,2 @@ console.log(decrypted); // Uint8Array([0x01, 0x01, 0x01])

(async () => {
await openpgp.initWorker({ path: 'openpgp.worker.js' }); // set the relative web worker path
// put keys in backtick (``) to avoid errors caused by spaces or tabs

@@ -206,15 +221,21 @@ const publicKeyArmored = `-----BEGIN PGP PUBLIC KEY BLOCK-----

const { keys: [privateKey] } = await openpgp.key.readArmored(privateKeyArmored);
const publicKey = await openpgp.readKey({ armoredKey: publicKeyArmored });
const privateKey = await openpgp.readKey({ armoredKey: privateKeyArmored });
await privateKey.decrypt(passphrase);
const { data: encrypted } = await openpgp.encrypt({
message: openpgp.message.fromText('Hello, World!'), // input as Message object
publicKeys: (await openpgp.key.readArmored(publicKeyArmored)).keys, // for encryption
privateKeys: [privateKey] // for signing (optional)
const encrypted = await openpgp.encrypt({
message: openpgp.Message.fromText('Hello, World!'), // input as Message object
publicKeys: publicKey, // for encryption
privateKeys: privateKey // for signing (optional)
});
console.log(encrypted); // '-----BEGIN PGP MESSAGE ... END PGP MESSAGE-----'
const message = await openpgp.readMessage({
armoredMessage: encrypted // parse armored message
});
const { data: decrypted } = await openpgp.decrypt({
message: await openpgp.message.readArmored(encrypted), // parse armored message
publicKeys: (await openpgp.key.readArmored(publicKeyArmored)).keys, // for verification (optional)
privateKeys: [privateKey] // for decryption
message,
publicKeys: publicKey, // for verification (optional)
privateKeys: privateKey // for decryption
});

@@ -243,13 +264,12 @@ console.log(decrypted); // 'Hello, World!'

const { keys: [privateKey] } = await openpgp.key.readArmored(privateKeyArmored);
const publicKeys = await Promise.all(publicKeysArmored.map(armoredKey => openpgp.readKey({ armoredKey })));
const privateKey = await openpgp.readKey({ armoredKey: privateKeyArmored });
await privateKey.decrypt(passphrase)
const publicKeys = await Promise.all(publicKeysArmored.map(async (key) => {
return (await openpgp.key.readArmored(key)).keys[0];
}));
const { data: encrypted } = await openpgp.encrypt({
message: openpgp.message.fromText(message), // input as Message object
publicKeys, // for encryption
privateKeys: [privateKey] // for signing (optional)
const message = openpgp.Message.fromText(message);
const encrypted = await openpgp.encrypt({
message:, // input as Message object
publicKeys, // for encryption
privateKeys: privateKey // for signing (optional)
});

@@ -268,6 +288,7 @@ console.log(encrypted); // '-----BEGIN PGP MESSAGE ... END PGP MESSAGE-----'

(async () => {
const message = openpgp.Message.fromBinary(new Uint8Array([0x01, 0x02, 0x03])); // or .fromText('string')
const encrypted = await openpgp.encrypt({
message: openpgp.message.fromBinary(new Uint8Array([0x01, 0x02, 0x03])), // or .fromText('string')
passwords: ['secret stuff'], // multiple passwords possible
compression: openpgp.enums.compression.zip // compress the data with zip
message,
passwords: ['secret stuff'], // multiple passwords possible
compression: openpgp.enums.compression.zip // compress the data with zip
});

@@ -292,3 +313,3 @@ })();

(async () => {
const readableStream = new ReadableStream({
const readableStream = new openpgp.stream.ReadableStream({
start(controller) {

@@ -300,8 +321,9 @@ controller.enqueue(new Uint8Array([0x01, 0x02, 0x03]));

const { message } = await openpgp.encrypt({
message: openpgp.message.fromBinary(readableStream), // input as Message object
passwords: ['secret stuff'], // multiple passwords possible
armor: false // don't ASCII armor (for Uint8Array output)
const message = openpgp.Message.fromBinary(readableStream);
const encrypted = await openpgp.encrypt({
message, // input as Message object
passwords: ['secret stuff'], // multiple passwords possible
armor: false // don't ASCII armor (for Uint8Array output)
});
const encrypted = message.packets.write(); // get raw encrypted packets as ReadableStream<Uint8Array>
console.log(encrypted); // raw encrypted packets as ReadableStream<Uint8Array>

@@ -342,6 +364,8 @@ // Either pipe the above stream somewhere, pass it to another function,

const privateKey = (await openpgp.key.readArmored([privateKeyArmored])).keys[0];
const publicKey = await openpgp.readKey({ armoredKey: publicKeyArmored });
const privateKey = await openpgp.readKey({ armoredKey: privateKeyArmored });
await privateKey.decrypt(passphrase);
const readableStream = new ReadableStream({
const readableStream = new openpgp.stream.ReadableStream({
start(controller) {

@@ -354,14 +378,18 @@ controller.enqueue('Hello, world!');

const encrypted = await openpgp.encrypt({
message: openpgp.message.fromText(readableStream), // input as Message object
publicKeys: (await openpgp.key.readArmored(publicKeyArmored)).keys, // for encryption
privateKeys: [privateKey] // for signing (optional)
message: openpgp.Message.fromText(readableStream), // input as Message object
publicKeys: publicKey, // for encryption
privateKeys: privateKey // for signing (optional)
});
const ciphertext = encrypted.data; // ReadableStream containing '-----BEGIN PGP MESSAGE ... END PGP MESSAGE-----'
console.log(encrypted); // ReadableStream containing '-----BEGIN PGP MESSAGE ... END PGP MESSAGE-----'
const message = await openpgp.readMessage({
armoredMessage: encrypted // parse armored message
});
const decrypted = await openpgp.decrypt({
message: await openpgp.message.readArmored(ciphertext), // parse armored message
publicKeys: (await openpgp.key.readArmored(publicKeyArmored)).keys, // for verification (optional)
privateKeys: [privateKey] // for decryption
message,
publicKeys: publicKey, // for verification (optional)
privateKeys: privateKey // for decryption
});
const plaintext = await openpgp.stream.readToEnd(decrypted.data); // 'Hello, World!'
const plaintext = await openpgp.stream.readToEnd(decrypted.data);
console.log(plaintext); // 'Hello, World!'
})();

@@ -373,6 +401,6 @@ ```

ECC keys:
ECC keys (smaller and faster to generate):
Possible values for `curve` are: `curve25519`, `ed25519`, `p256`, `p384`, `p521`, `secp256k1`,
`brainpoolP256r1`, `brainpoolP384r1`, or `brainpoolP512r1`.
Possible values for `curve` are: `curve25519`, `ed25519`, `p256`, `p384`, `p521`,
`brainpoolP256r1`, `brainpoolP384r1`, `brainpoolP512r1`, and `secp256k1`.
Note that both the `curve25519` and `ed25519` options generate a primary key for signing using Ed25519

@@ -384,5 +412,6 @@ and a subkey for encryption using Curve25519.

const { privateKeyArmored, publicKeyArmored, revocationCertificate } = await openpgp.generateKey({
type: 'ecc', // Type of the key, defaults to ECC
curve: 'curve25519', // ECC curve name, defaults to curve25519
userIds: [{ name: 'Jon Smith', email: 'jon@example.com' }], // you can pass multiple user IDs
curve: 'ed25519', // ECC curve name
passphrase: 'super long and hard to guess secret' // protects the private key
passphrase: 'super long and hard to guess secret' // protects the private key
});

@@ -396,3 +425,3 @@

RSA keys:
RSA keys (increased compatibility):

@@ -402,5 +431,6 @@ ```js

const key = await openpgp.generateKey({
type: 'rsa', // Type of the key
rsaBits: 4096, // RSA key size (defaults to 4096 bits)
userIds: [{ name: 'Jon Smith', email: 'jon@example.com' }], // you can pass multiple user IDs
rsaBits: 4096, // RSA key size
passphrase: 'super long and hard to guess secret' // protects the private key
passphrase: 'super long and hard to guess secret' // protects the private key
});

@@ -416,3 +446,3 @@ })();

const { publicKeyArmored: revokedKeyArmored } = await openpgp.revokeKey({
key: (await openpgp.key.readArmored(publicKeyArmored)).keys[0],
key: await openpgp.readKey({ armoredKey: publicKeyArmored }),
revocationCertificate

@@ -428,3 +458,3 @@ });

const { publicKeyArmored, publicKey } = await openpgp.revokeKey({
key: (await openpgp.key.readArmored(privateKeyArmored)).keys[0]
key: await openpgp.readKey({ armoredKey: privateKeyArmored })
});

@@ -443,3 +473,3 @@ })();

});
var { keys: [publicKey] } = await openpgp.key.readArmored(publicKeyArmored);
let publicKey = await openpgp.readKey({ armoredKey: publicKeyArmored });
})();

@@ -474,14 +504,20 @@ ```

const { keys: [privateKey] } = await openpgp.key.readArmored(privateKeyArmored);
const publicKey = await openpgp.readKey({ armoredKey: publicKeyArmored });
const privateKey = await openpgp.readKey({ armoredKey: privateKeyArmored });
await privateKey.decrypt(passphrase);
const { data: cleartext } = await openpgp.sign({
message: openpgp.cleartext.fromText('Hello, World!'), // CleartextMessage or Message object
privateKeys: [privateKey] // for signing
const unsignedMessage = openpgp.CleartextMessage.fromText('Hello, World!');
const cleartextMessage = await openpgp.sign({
message: unsignedMessage, // CleartextMessage or Message object
privateKeys: privateKey // for signing
});
console.log(cleartext); // '-----BEGIN PGP SIGNED MESSAGE ... END PGP SIGNATURE-----'
console.log(cleartextMessage); // '-----BEGIN PGP SIGNED MESSAGE ... END PGP SIGNATURE-----'
const signedMessage = await openpgp.readCleartextMessage({
cleartextMessage // parse armored message
});
const verified = await openpgp.verify({
message: await openpgp.cleartext.readArmored(cleartext), // parse armored message
publicKeys: (await openpgp.key.readArmored(publicKeyArmored)).keys // for verification
message: signedMessage,
publicKeys: publicKey // for verification
});

@@ -509,8 +545,11 @@ const { valid } = verified.signatures[0];

const { keys: [privateKey] } = await openpgp.key.readArmored(privateKeyArmored);
const publicKey = await openpgp.readKey({ armoredKey: publicKeyArmored });
const privateKey = await openpgp.readKey({ armoredKey: privateKeyArmored });
await privateKey.decrypt(passphrase);
const { signature: detachedSignature } = await openpgp.sign({
message: openpgp.cleartext.fromText('Hello, World!'), // CleartextMessage or Message object
privateKeys: [privateKey], // for signing
const cleartextMessage = openpgp.CleartextMessage.fromText('Hello, World!');
const detachedSignature = await openpgp.sign({
message: cleartextMessage, // CleartextMessage or Message object
privateKeys: privateKey, // for signing
detached: true

@@ -520,6 +559,9 @@ });

const signature = await openpgp.readSignature({
armoredSignature: detachedSignature // parse detached signature
});
const verified = await openpgp.verify({
message: openpgp.cleartext.fromText('Hello, World!'), // CleartextMessage or Message object
signature: await openpgp.signature.readArmored(detachedSignature), // parse detached signature
publicKeys: (await openpgp.key.readArmored(publicKeyArmored)).keys // for verification
message: cleartextMessage, // CleartextMessage or Message object
signature,
publicKeys: publicKey // for verification
});

@@ -539,3 +581,3 @@ const { valid } = verified.signatures[0];

(async () => {
var readableStream = new ReadableStream({
var readableStream = new openpgp.stream.ReadableStream({
start(controller) {

@@ -555,8 +597,9 @@ controller.enqueue(new Uint8Array([0x01, 0x02, 0x03]));

const { keys: [privateKey] } = await openpgp.key.readArmored(privateKeyArmored);
const privateKey = await openpgp.readKey({ armoredKey: privateKeyArmored });
await privateKey.decrypt(passphrase);
const { data: signatureArmored } = await openpgp.sign({
message: openpgp.message.fromBinary(readableStream), // or .fromText(readableStream: ReadableStream<String>)
privateKeys: [privateKey] // for signing
const message = openpgp.Message.fromBinary(readableStream); // or .fromText(readableStream: ReadableStream<String>)
const signatureArmored = await openpgp.sign({
message,
privateKeys: privateKey // for signing
});

@@ -566,4 +609,4 @@ console.log(signatureArmored); // ReadableStream containing '-----BEGIN PGP MESSAGE ... END PGP MESSAGE-----'

const verified = await openpgp.verify({
message: await openpgp.message.readArmored(signatureArmored), // parse armored signature
publicKeys: (await openpgp.key.readArmored(publicKeyArmored)).keys // for verification
message: await openpgp.readMessage({ armoredMessage: signatureArmored }), // parse armored signature
publicKeys: await openpgp.readKey({ armoredKey: publicKeyArmored }) // for verification
});

@@ -587,6 +630,4 @@

A jsdoc build of our code comments is available at [doc/index.html](https://openpgpjs.org/openpgpjs/doc/index.html). Public calls should generally be made through the OpenPGP object [doc/openpgp.html](https://openpgpjs.org/openpgpjs/doc/module-openpgp.html).
The full documentation is available at [openpgpjs.org](https://openpgpjs.org/openpgpjs/).
For the documentation of `openpgp.stream`, see the documentation of [the web-stream-tools dependency](https://openpgpjs.org/web-stream-tools/).
### Security Audit

@@ -608,5 +649,5 @@

For debugging browser errors, you can open `test/unittests.html` in a browser or, after running the following command, open [`http://localhost:3000/test/unittests.html`](http://localhost:3000/test/unittests.html):
For debugging browser errors, you can run `npm start` and open [`http://localhost:8080/test/unittests.html`](http://localhost:8080/test/unittests.html) in a browser, or run the following command:
grunt browsertest
npm run browsertest

@@ -620,11 +661,1 @@ ### How do I get involved?

[GNU Lesser General Public License](https://www.gnu.org/licenses/lgpl-3.0.en.html) (3.0 or any later version). Please take a look at the [LICENSE](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.
* [https://www.hanewin.net/encrypt/](https://www.hanewin.net/encrypt/)
* [https://github.com/seancolyer/gmail-crypt](https://github.com/seancolyer/gmail-crypt)
* [https://github.com/mete0r/jspg](https://github.com/mete0r/jspg)
* [https://github.com/GPGTools/Mobile/wiki/Introduction](https://github.com/GPGTools/Mobile/wiki/Introduction)
* [https://github.com/gmontalvoriv/mailock](https://github.com/gmontalvoriv/mailock)

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc