Installations
npm install openpgp
Releases
v6.0.1
Published on 21 Nov 2024
v6.0.0
Published on 04 Nov 2024
v6.0.0-beta.3.patch.1
Published on 11 Sept 2024
v6.0.0-beta.3.patch.0
Published on 09 Sept 2024
v6.0.0-beta.3
Published on 05 Sept 2024
v6.0.0-beta.2
Published on 05 Jul 2024
Developer
Developer Guide
Module System
ESM, UMD
Min. Node Version
>= 18.0.0
Typescript Support
Yes
Node Version
22.8.0
NPM Version
10.8.2
Statistics
5,690 Stars
2,551 Commits
798 Forks
174 Watching
6 Branches
112 Contributors
Updated on 25 Nov 2024
Languages
JavaScript (97.97%)
TypeScript (1.95%)
HTML (0.06%)
Shell (0.02%)
Total Downloads
Cumulative downloads
Total Downloads
40,695,270
Last day
6.8%
81,240
Compared to previous day
Last week
1.9%
470,963
Compared to previous week
Last month
14.4%
1,807,275
Compared to previous month
Last year
55.1%
17,438,494
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
46
OpenPGP.js
OpenPGP.js is a JavaScript implementation of the OpenPGP protocol. It implements RFC 9580 (superseding RFC 4880 and RFC 4880bis).
Table of Contents
- OpenPGP.js
- Platform Support
- Performance
- Getting started
- Examples
- Encrypt and decrypt Uint8Array data with a password
- Encrypt and decrypt String data with PGP keys
- Encrypt symmetrically with compression
- Streaming encrypt Uint8Array data with a password
- Streaming encrypt and decrypt String data with PGP keys
- Generate new key pair
- Revoke a key
- Sign and verify cleartext messages
- Create and verify detached signatures
- Streaming sign and verify Uint8Array data
- Documentation
- Security Audit
- Security recommendations
- Development
- How do I get involved?
- License
Platform Support
-
The
dist/openpgp.min.js
(or.mjs
) bundle works with recent versions of Chrome, Firefox, Edge and Safari 14+. -
The
dist/node/openpgp.min.mjs
(or.cjs
) bundle works in Node.js v18+: it is used by default when youimport ... from 'openpgp'
(orrequire('openpgp')
, respectively). -
Support for the Web Cryptography API's
SubtleCrypto
is required.- In browsers,
SubtleCrypto
is only available in secure contexts. - In supported versions of Node.js,
SubtleCrypto
is always available.
- In browsers,
-
Support for the Web Streams API is required.
- In browsers: the latest versions of Chrome, Firefox, Edge and Safari support Streams, including
TransformStream
s. These are needed if you use the library with stream inputs. In previous versions of OpenPGP.js, Web Streams were automatically polyfilled by the library, but from v6 this task is left up to the library user, due to the more extensive browser support, and the polyfilling side-effects. If you're working with older browsers versions which do not implement e.g. TransformStreams, you can manually load the Web Streams polyfill. Please note that when you load the polyfills, the globalReadableStream
property (if it exists) gets overwritten with the polyfill version. In some edge cases, you might need to use the nativeReadableStream
(for example when using it to create aResponse
object), in which case you should store a reference to it before loading the polyfills. There is also the web-streams-adapter library to convert back and forth between them. - In Node.js: OpenPGP.js v6 no longer supports native Node
Readable
streams in inputs, and instead expects (and outputs) Node's Web Streams. Node v17+ includes utilities to convert from and to Web Streams.
- In browsers: the latest versions of Chrome, Firefox, Edge and Safari support Streams, including
Performance
-
Version 3.0.0 of the library introduced support for public-key cryptography using elliptic curves. We use native implementations on browsers and Node.js when available. Compared to RSA, 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 Yes* If native** nistP256 ECDH ECDSA Yes* Yes* If native** nistP384 ECDH ECDSA Yes* Yes* If native** nistP521 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** * when available
** these curves are only constant-time if the underlying native implementation is available and constant-time -
The platform's native Web Crypto API is used for performance. On Node.js the native crypto module is also used, in cases where it offers additional functionality.
-
The library implements authenticated encryption (AEAD) as per RFC 9580 using AES-GCM, OCB, or EAX. This makes symmetric encryption faster on platforms with native implementations. However, since the specification is very recent and other OpenPGP implementations are in the process of adopting it, the feature is currently behind a flag. Note: activating this setting can break compatibility with other OpenPGP implementations which have yet to implement the feature. You can enable it by setting
openpgp.config.aeadProtect = true
. Note that this setting has a different effect from the one in OpenPGP.js v5, which implemented support for a provisional version of AEAD from RFC 4880bis, which was modified in RFC 9580.You can change the AEAD mode by setting one of the following options:
openpgp.config.preferredAEADAlgorithm = openpgp.enums.aead.gcm; // Default, native in WebCrypto and Node.js openpgp.config.preferredAEADAlgorithm = openpgp.enums.aead.ocb; // Non-native, but supported across RFC 9580 implementations openpgp.config.preferredAEADAlgorithm = openpgp.enums.aead.eax; // Native in Node.js
Getting started
Node.js
Install OpenPGP.js using npm and save it in your dependencies:
1npm install --save openpgp
And import it as an ES module, from a .mjs file:
1import * as openpgp from 'openpgp';
Or as a CommonJS module:
1const openpgp = require('openpgp');
Deno (experimental)
Import as an ES6 module, using /dist/openpgp.mjs.
1import * as openpgp from './openpgpjs/dist/openpgp.mjs';
Browser (webpack)
Install OpenPGP.js using npm and save it in your devDependencies:
1npm install --save-dev openpgp
And import it as an ES6 module:
1import * as openpgp from 'openpgp';
You can also only import the functions you need, as follows:
1import { readMessage, decrypt } from 'openpgp';
Or, if you want to use the lightweight build (which is smaller, and lazily loads non-default curves on demand):
1import * as openpgp from 'openpgp/lightweight';
To test whether the lazy loading works, try to generate a key with a non-standard curve:
1import { generateKey } from 'openpgp/lightweight'; 2await generateKey({ curve: 'brainpoolP512r1', userIDs: [{ name: 'Test', email: 'test@test.com' }] });
For more examples of how to generate a key, see Generate new key pair. It is recommended to use curve25519
instead of brainpoolP512r1
by default.
Browser (plain files)
Grab openpgp.min.js
from unpkg.com/openpgp/dist, and load it in a script tag:
1<script src="openpgp.min.js"></script>
Or, to load OpenPGP.js as an ES6 module, grab openpgp.min.mjs
from unpkg.com/openpgp/dist, and import it as follows:
1<script type="module"> 2import * as openpgp from './openpgp.min.mjs'; 3</script>
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
.
TypeScript
Since TS is not fully integrated in the library, TS-only dependencies are currently listed as devDependencies
, so to compile the project you’ll need to add @openpgp/web-stream-tools
manually:
1npm install --save-dev @openpgp/web-stream-tools
If you notice missing or incorrect type definitions, feel free to open a PR.
Examples
Here are some examples of how to use OpenPGP.js v6. For more elaborate examples and working code, please check out the public API unit tests. If you're upgrading from v4 it might help to check out the changelog and documentation.
Encrypt and decrypt Uint8Array data with a password
Encryption will use the algorithm specified in config.preferredSymmetricAlgorithm (defaults to aes256), and decryption will use the algorithm used for encryption.
1(async () => { 2 const message = await openpgp.createMessage({ binary: new Uint8Array([0x01, 0x01, 0x01]) }); 3 const encrypted = await openpgp.encrypt({ 4 message, // input as Message object 5 passwords: ['secret stuff'], // multiple passwords possible 6 format: 'binary' // don't ASCII armor (for Uint8Array output) 7 }); 8 console.log(encrypted); // Uint8Array 9 10 const encryptedMessage = await openpgp.readMessage({ 11 binaryMessage: encrypted // parse encrypted bytes 12 }); 13 const { data: decrypted } = await openpgp.decrypt({ 14 message: encryptedMessage, 15 passwords: ['secret stuff'], // decrypt with password 16 format: 'binary' // output as Uint8Array 17 }); 18 console.log(decrypted); // Uint8Array([0x01, 0x01, 0x01]) 19})();
Encrypt and decrypt String data with PGP keys
Encryption will use the algorithm preferred by the public (encryption) key (defaults to aes256 for keys generated in OpenPGP.js), and decryption will use the algorithm used for encryption.
1const openpgp = require('openpgp'); // use as CommonJS, AMD, ES6 module or via window.openpgp 2 3(async () => { 4 // put keys in backtick (``) to avoid errors caused by spaces or tabs 5 const publicKeyArmored = `-----BEGIN PGP PUBLIC KEY BLOCK----- 6... 7-----END PGP PUBLIC KEY BLOCK-----`; 8 const privateKeyArmored = `-----BEGIN PGP PRIVATE KEY BLOCK----- 9... 10-----END PGP PRIVATE KEY BLOCK-----`; // encrypted private key 11 const passphrase = `yourPassphrase`; // what the private key is encrypted with 12 13 const publicKey = await openpgp.readKey({ armoredKey: publicKeyArmored }); 14 15 const privateKey = await openpgp.decryptKey({ 16 privateKey: await openpgp.readPrivateKey({ armoredKey: privateKeyArmored }), 17 passphrase 18 }); 19 20 const encrypted = await openpgp.encrypt({ 21 message: await openpgp.createMessage({ text: 'Hello, World!' }), // input as Message object 22 encryptionKeys: publicKey, 23 signingKeys: privateKey // optional 24 }); 25 console.log(encrypted); // '-----BEGIN PGP MESSAGE ... END PGP MESSAGE-----' 26 27 const message = await openpgp.readMessage({ 28 armoredMessage: encrypted // parse armored message 29 }); 30 const { data: decrypted, signatures } = await openpgp.decrypt({ 31 message, 32 verificationKeys: publicKey, // optional 33 decryptionKeys: privateKey 34 }); 35 console.log(decrypted); // 'Hello, World!' 36 // check signature validity (signed messages only) 37 try { 38 await signatures[0].verified; // throws on invalid signature 39 console.log('Signature is valid'); 40 } catch (e) { 41 throw new Error('Signature could not be verified: ' + e.message); 42 } 43})();
Encrypt to multiple public keys:
1(async () => { 2 const publicKeysArmored = [ 3 `-----BEGIN PGP PUBLIC KEY BLOCK----- 4... 5-----END PGP PUBLIC KEY BLOCK-----`, 6 `-----BEGIN PGP PUBLIC KEY BLOCK----- 7... 8-----END PGP PUBLIC KEY BLOCK-----` 9 ]; 10 const privateKeyArmored = `-----BEGIN PGP PRIVATE KEY BLOCK----- 11... 12-----END PGP PRIVATE KEY BLOCK-----`; // encrypted private key 13 const passphrase = `yourPassphrase`; // what the private key is encrypted with 14 const plaintext = 'Hello, World!'; 15 16 const publicKeys = await Promise.all(publicKeysArmored.map(armoredKey => openpgp.readKey({ armoredKey }))); 17 18 const privateKey = await openpgp.decryptKey({ 19 privateKey: await openpgp.readKey({ armoredKey: privateKeyArmored }), 20 passphrase 21 }); 22 23 const message = await openpgp.createMessage({ text: plaintext }); 24 const encrypted = await openpgp.encrypt({ 25 message, // input as Message object 26 encryptionKeys: publicKeys, 27 signingKeys: privateKey // optional 28 }); 29 console.log(encrypted); // '-----BEGIN PGP MESSAGE ... END PGP MESSAGE-----' 30})();
If you expect an encrypted message to be signed with one of the public keys you have, and do not want to trust the decrypted data otherwise, you can pass the decryption option expectSigned = true
, so that the decryption operation will fail if no valid signature is found:
1(async () => { 2 // put keys in backtick (``) to avoid errors caused by spaces or tabs 3 const publicKeyArmored = `-----BEGIN PGP PUBLIC KEY BLOCK----- 4... 5-----END PGP PUBLIC KEY BLOCK-----`; 6 const privateKeyArmored = `-----BEGIN PGP PRIVATE KEY BLOCK----- 7... 8-----END PGP PRIVATE KEY BLOCK-----`; // encrypted private key 9 const passphrase = `yourPassphrase`; // what the private key is encrypted with 10 11 const publicKey = await openpgp.readKey({ armoredKey: publicKeyArmored }); 12 13 const privateKey = await openpgp.decryptKey({ 14 privateKey: await openpgp.readPrivateKey({ armoredKey: privateKeyArmored }), 15 passphrase 16 }); 17 18 const encryptedAndSignedMessage = `-----BEGIN PGP MESSAGE----- 19... 20-----END PGP MESSAGE-----`; 21 22 const message = await openpgp.readMessage({ 23 armoredMessage: encryptedAndSignedMessage // parse armored message 24 }); 25 // decryption will fail if all signatures are invalid or missing 26 const { data: decrypted, signatures } = await openpgp.decrypt({ 27 message, 28 decryptionKeys: privateKey, 29 expectSigned: true, 30 verificationKeys: publicKey, // mandatory with expectSigned=true 31 }); 32 console.log(decrypted); // 'Hello, World!' 33})();
Encrypt symmetrically with compression
By default, encrypt
will not use any compression when encrypting symmetrically only (i.e. when no encryptionKeys
are given).
It's possible to change that behaviour by enabling compression through the config, either for the single encryption:
1(async () => { 2 const message = await openpgp.createMessage({ binary: new Uint8Array([0x01, 0x02, 0x03]) }); // or createMessage({ text: 'string' }) 3 const encrypted = await openpgp.encrypt({ 4 message, 5 passwords: ['secret stuff'], // multiple passwords possible 6 config: { preferredCompressionAlgorithm: openpgp.enums.compression.zlib } // compress the data with zlib 7 }); 8})();
or by changing the default global configuration:
1openpgp.config.preferredCompressionAlgorithm = openpgp.enums.compression.zlib
Where the value can be any of:
openpgp.enums.compression.zip
openpgp.enums.compression.zlib
openpgp.enums.compression.uncompressed
(default)
Streaming encrypt Uint8Array data with a password
1(async () => { 2 const readableStream = new ReadableStream({ 3 start(controller) { 4 controller.enqueue(new Uint8Array([0x01, 0x02, 0x03])); 5 controller.close(); 6 } 7 }); 8 9 const message = await openpgp.createMessage({ binary: readableStream }); 10 const encrypted = await openpgp.encrypt({ 11 message, // input as Message object 12 passwords: ['secret stuff'], // multiple passwords possible 13 format: 'binary' // don't ASCII armor (for Uint8Array output) 14 }); 15 console.log(encrypted); // raw encrypted packets as ReadableStream<Uint8Array> 16 17 // Either pipe the above stream somewhere, pass it to another function, 18 // or read it manually as follows: 19 for await (const chunk of encrypted) { 20 console.log('new chunk:', chunk); // Uint8Array 21 } 22})();
For more information on using ReadableStreams (both in browsers and Node.js), see the MDN Documentation on the Streams API .
Streaming encrypt and decrypt String data with PGP keys
1(async () => { 2 const publicKeyArmored = `-----BEGIN PGP PUBLIC KEY BLOCK----- 3... 4-----END PGP PUBLIC KEY BLOCK-----`; // Public key 5 const privateKeyArmored = `-----BEGIN PGP PRIVATE KEY BLOCK----- 6... 7-----END PGP PRIVATE KEY BLOCK-----`; // Encrypted private key 8 const passphrase = `yourPassphrase`; // Password that private key is encrypted with 9 10 const publicKey = await openpgp.readKey({ armoredKey: publicKeyArmored }); 11 12 const privateKey = await openpgp.decryptKey({ 13 privateKey: await openpgp.readPrivateKey({ armoredKey: privateKeyArmored }), 14 passphrase 15 }); 16 17 const readableStream = new ReadableStream({ 18 start(controller) { 19 controller.enqueue('Hello, world!'); 20 controller.close(); 21 } 22 }); 23 24 const encrypted = await openpgp.encrypt({ 25 message: await openpgp.createMessage({ text: readableStream }), // input as Message object 26 encryptionKeys: publicKey, 27 signingKeys: privateKey // optional 28 }); 29 console.log(encrypted); // ReadableStream containing '-----BEGIN PGP MESSAGE ... END PGP MESSAGE-----' 30 31 const message = await openpgp.readMessage({ 32 armoredMessage: encrypted // parse armored message 33 }); 34 const decrypted = await openpgp.decrypt({ 35 message, 36 verificationKeys: publicKey, // optional 37 decryptionKeys: privateKey 38 }); 39 const chunks = []; 40 for await (const chunk of decrypted.data) { 41 chunks.push(chunk); 42 } 43 const plaintext = chunks.join(''); 44 console.log(plaintext); // 'Hello, World!' 45})();
Generate new key pair
ECC keys (smaller and faster to generate):
Possible values for curve
are: curve25519
, ed25519
, nistP256
, nistP384
, nistP521
,
brainpoolP256r1
, brainpoolP384r1
, brainpoolP512r1
, and secp256k1
.
Note that both the curve25519
and ed25519
options generate a primary key for signing using Ed25519
and a subkey for encryption using Curve25519.
1(async () => {
2 const { privateKey, publicKey, revocationCertificate } = await openpgp.generateKey({
3 type: 'ecc', // Type of the key, defaults to ECC
4 curve: 'curve25519', // ECC curve name, defaults to curve25519
5 userIDs: [{ name: 'Jon Smith', email: 'jon@example.com' }], // you can pass multiple user IDs
6 passphrase: 'super long and hard to guess secret', // protects the private key
7 format: 'armored' // output key format, defaults to 'armored' (other options: 'binary' or 'object')
8 });
9
10 console.log(privateKey); // '-----BEGIN PGP PRIVATE KEY BLOCK ... '
11 console.log(publicKey); // '-----BEGIN PGP PUBLIC KEY BLOCK ... '
12 console.log(revocationCertificate); // '-----BEGIN PGP PUBLIC KEY BLOCK ... '
13})();
RSA keys (increased compatibility):
1(async () => { 2 const { privateKey, publicKey } = await openpgp.generateKey({ 3 type: 'rsa', // Type of the key 4 rsaBits: 4096, // RSA key size (defaults to 4096 bits) 5 userIDs: [{ name: 'Jon Smith', email: 'jon@example.com' }], // you can pass multiple user IDs 6 passphrase: 'super long and hard to guess secret' // protects the private key 7 }); 8})();
Revoke a key
Using a revocation certificate:
1(async () => { 2 const { publicKey: revokedKeyArmored } = await openpgp.revokeKey({ 3 key: await openpgp.readKey({ armoredKey: publicKeyArmored }), 4 revocationCertificate, 5 format: 'armored' // output armored keys 6 }); 7 console.log(revokedKeyArmored); // '-----BEGIN PGP PUBLIC KEY BLOCK ... ' 8})();
Using the private key:
1(async () => { 2 const { publicKey: revokedKeyArmored } = await openpgp.revokeKey({ 3 key: await openpgp.readKey({ armoredKey: privateKeyArmored }), 4 format: 'armored' // output armored keys 5 }); 6 console.log(revokedKeyArmored); // '-----BEGIN PGP PUBLIC KEY BLOCK ... ' 7})();
Sign and verify cleartext messages
1(async () => { 2 const publicKeyArmored = `-----BEGIN PGP PUBLIC KEY BLOCK----- 3... 4-----END PGP PUBLIC KEY BLOCK-----`; 5 const privateKeyArmored = `-----BEGIN PGP PRIVATE KEY BLOCK----- 6... 7-----END PGP PRIVATE KEY BLOCK-----`; // encrypted private key 8 const passphrase = `yourPassphrase`; // what the private key is encrypted with 9 10 const publicKey = await openpgp.readKey({ armoredKey: publicKeyArmored }); 11 12 const privateKey = await openpgp.decryptKey({ 13 privateKey: await openpgp.readPrivateKey({ armoredKey: privateKeyArmored }), 14 passphrase 15 }); 16 17 const unsignedMessage = await openpgp.createCleartextMessage({ text: 'Hello, World!' }); 18 const cleartextMessage = await openpgp.sign({ 19 message: unsignedMessage, // CleartextMessage or Message object 20 signingKeys: privateKey 21 }); 22 console.log(cleartextMessage); // '-----BEGIN PGP SIGNED MESSAGE ... END PGP SIGNATURE-----' 23 24 const signedMessage = await openpgp.readCleartextMessage({ 25 cleartextMessage // parse armored message 26 }); 27 const verificationResult = await openpgp.verify({ 28 message: signedMessage, 29 verificationKeys: publicKey 30 }); 31 const { verified, keyID } = verificationResult.signatures[0]; 32 try { 33 await verified; // throws on invalid signature 34 console.log('Signed by key id ' + keyID.toHex()); 35 } catch (e) { 36 throw new Error('Signature could not be verified: ' + e.message); 37 } 38})();
Create and verify detached signatures
1(async () => { 2 const publicKeyArmored = `-----BEGIN PGP PUBLIC KEY BLOCK----- 3... 4-----END PGP PUBLIC KEY BLOCK-----`; 5 const privateKeyArmored = `-----BEGIN PGP PRIVATE KEY BLOCK----- 6... 7-----END PGP PRIVATE KEY BLOCK-----`; // encrypted private key 8 const passphrase = `yourPassphrase`; // what the private key is encrypted with 9 10 const publicKey = await openpgp.readKey({ armoredKey: publicKeyArmored }); 11 12 const privateKey = await openpgp.decryptKey({ 13 privateKey: await openpgp.readPrivateKey({ armoredKey: privateKeyArmored }), 14 passphrase 15 }); 16 17 const message = await openpgp.createMessage({ text: 'Hello, World!' }); 18 const detachedSignature = await openpgp.sign({ 19 message, // Message object 20 signingKeys: privateKey, 21 detached: true 22 }); 23 console.log(detachedSignature); 24 25 const signature = await openpgp.readSignature({ 26 armoredSignature: detachedSignature // parse detached signature 27 }); 28 const verificationResult = await openpgp.verify({ 29 message, // Message object 30 signature, 31 verificationKeys: publicKey 32 }); 33 const { verified, keyID } = verificationResult.signatures[0]; 34 try { 35 await verified; // throws on invalid signature 36 console.log('Signed by key id ' + keyID.toHex()); 37 } catch (e) { 38 throw new Error('Signature could not be verified: ' + e.message); 39 } 40})();
Streaming sign and verify Uint8Array data
1(async () => { 2 var readableStream = new ReadableStream({ 3 start(controller) { 4 controller.enqueue(new Uint8Array([0x01, 0x02, 0x03])); 5 controller.close(); 6 } 7 }); 8 9 const publicKeyArmored = `-----BEGIN PGP PUBLIC KEY BLOCK----- 10... 11-----END PGP PUBLIC KEY BLOCK-----`; 12 const privateKeyArmored = `-----BEGIN PGP PRIVATE KEY BLOCK----- 13... 14-----END PGP PRIVATE KEY BLOCK-----`; // encrypted private key 15 const passphrase = `yourPassphrase`; // what the private key is encrypted with 16 17 const privateKey = await openpgp.decryptKey({ 18 privateKey: await openpgp.readPrivateKey({ armoredKey: privateKeyArmored }), 19 passphrase 20 }); 21 22 const message = await openpgp.createMessage({ binary: readableStream }); // or createMessage({ text: ReadableStream<String> }) 23 const signatureArmored = await openpgp.sign({ 24 message, 25 signingKeys: privateKey 26 }); 27 console.log(signatureArmored); // ReadableStream containing '-----BEGIN PGP MESSAGE ... END PGP MESSAGE-----' 28 29 const verificationResult = await openpgp.verify({ 30 message: await openpgp.readMessage({ armoredMessage: signatureArmored }), // parse armored signature 31 verificationKeys: await openpgp.readKey({ armoredKey: publicKeyArmored }) 32 }); 33 34 for await (const chunk of verificationResult.data) {} 35 // Note: you *have* to read `verificationResult.data` in some way or other, 36 // even if you don't need it, as that is what triggers the 37 // verification of the data. 38 39 try { 40 await verificationResult.signatures[0].verified; // throws on invalid signature 41 console.log('Signed by key id ' + verificationResult.signatures[0].keyID.toHex()); 42 } catch (e) { 43 throw new Error('Signature could not be verified: ' + e.message); 44 } 45})();
Documentation
The full documentation is available at openpgpjs.org.
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:
npm install && npm test
For debugging browser errors, run the following command:
npm run browsertest
How do I get involved?
You want to help, great! It's probably best to send us a message on Gitter before you start your undertaking, to make sure nobody else is working on it, and so we can discuss the best course of action. Other than that, just 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.
Stable Version
The latest stable version of the package.
Stable Version
6.0.1
HIGH
3
7.5/10
Summary
OpenPGP 1.2.0 and earlier decrypts arbitrary messages
Affected Versions
< 1.3.0
Patched Versions
1.3.0
7.5/10
Summary
Improper Key Verification in openpgp
Affected Versions
<= 4.1.2
Patched Versions
4.2.0
7.5/10
Summary
Message Signature Bypass in openpgp
Affected Versions
<= 4.1.2
Patched Versions
4.2.0
MODERATE
3
4.3/10
Summary
Cleartext Signed Message Signature Spoofing in openpgp
Affected Versions
>= 5.0.0, < 5.10.1
Patched Versions
5.10.1
4.3/10
Summary
Cleartext Signed Message Signature Spoofing in openpgp
Affected Versions
< 4.10.11
Patched Versions
4.10.11
5.9/10
Summary
Invalid Curve Attack in openpgp
Affected Versions
< 4.3.0
Patched Versions
4.3.0
Reason
no dangerous workflow patterns detected
Reason
security policy file detected
Details
- Info: security policy file detected: SECURITY.md:1
- Info: Found linked content: SECURITY.md:1
- Info: Found disclosure, vulnerability, and/or timelines in security policy: SECURITY.md:1
- Info: Found text in security policy: SECURITY.md:1
Reason
30 commit(s) and 5 issue activity found in the last 90 days -- score normalized to 10
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: GNU Lesser General Public License v3.0: LICENSE:0
Reason
3 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-mxhp-79qh-mcx6
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
Reason
Found 8/16 approved changesets -- score normalized to 5
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
- Info: Possibly incomplete results: error parsing shell code: invalid parameter name: .github/workflows/tests.yml:91
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/benchmark.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/openpgpjs/openpgpjs/benchmark.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/benchmark.yml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/openpgpjs/openpgpjs/benchmark.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/benchmark.yml:22: update your workflow using https://app.stepsecurity.io/secureworkflow/openpgpjs/openpgpjs/benchmark.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/benchmark.yml:39: update your workflow using https://app.stepsecurity.io/secureworkflow/openpgpjs/openpgpjs/benchmark.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/benchmark.yml:55: update your workflow using https://app.stepsecurity.io/secureworkflow/openpgpjs/openpgpjs/benchmark.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/docs.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/openpgpjs/openpgpjs/docs.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/docs.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/openpgpjs/openpgpjs/docs.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/sop-test-suite.yml:75: update your workflow using https://app.stepsecurity.io/secureworkflow/openpgpjs/openpgpjs/sop-test-suite.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/sop-test-suite.yml:78: update your workflow using https://app.stepsecurity.io/secureworkflow/openpgpjs/openpgpjs/sop-test-suite.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/sop-test-suite.yml:82: update your workflow using https://app.stepsecurity.io/secureworkflow/openpgpjs/openpgpjs/sop-test-suite.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/sop-test-suite.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/openpgpjs/openpgpjs/sop-test-suite.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/sop-test-suite.yml:22: update your workflow using https://app.stepsecurity.io/secureworkflow/openpgpjs/openpgpjs/sop-test-suite.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/sop-test-suite.yml:33: update your workflow using https://app.stepsecurity.io/secureworkflow/openpgpjs/openpgpjs/sop-test-suite.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/sop-test-suite.yml:59: update your workflow using https://app.stepsecurity.io/secureworkflow/openpgpjs/openpgpjs/sop-test-suite.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/sop-test-suite.yml:64: update your workflow using https://app.stepsecurity.io/secureworkflow/openpgpjs/openpgpjs/sop-test-suite.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/tests.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/openpgpjs/openpgpjs/tests.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/tests.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/openpgpjs/openpgpjs/tests.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/tests.yml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/openpgpjs/openpgpjs/tests.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/tests.yml:41: update your workflow using https://app.stepsecurity.io/secureworkflow/openpgpjs/openpgpjs/tests.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/tests.yml:42: update your workflow using https://app.stepsecurity.io/secureworkflow/openpgpjs/openpgpjs/tests.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/tests.yml:47: update your workflow using https://app.stepsecurity.io/secureworkflow/openpgpjs/openpgpjs/tests.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/tests.yml:71: update your workflow using https://app.stepsecurity.io/secureworkflow/openpgpjs/openpgpjs/tests.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/tests.yml:72: update your workflow using https://app.stepsecurity.io/secureworkflow/openpgpjs/openpgpjs/tests.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/tests.yml:75: update your workflow using https://app.stepsecurity.io/secureworkflow/openpgpjs/openpgpjs/tests.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/tests.yml:98: update your workflow using https://app.stepsecurity.io/secureworkflow/openpgpjs/openpgpjs/tests.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/tests.yml:128: update your workflow using https://app.stepsecurity.io/secureworkflow/openpgpjs/openpgpjs/tests.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/tests.yml:129: update your workflow using https://app.stepsecurity.io/secureworkflow/openpgpjs/openpgpjs/tests.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/tests.yml:132: update your workflow using https://app.stepsecurity.io/secureworkflow/openpgpjs/openpgpjs/tests.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/tests.yml:144: update your workflow using https://app.stepsecurity.io/secureworkflow/openpgpjs/openpgpjs/tests.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/tests.yml:153: update your workflow using https://app.stepsecurity.io/secureworkflow/openpgpjs/openpgpjs/tests.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/tests.yml:175: update your workflow using https://app.stepsecurity.io/secureworkflow/openpgpjs/openpgpjs/tests.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/tests.yml:176: update your workflow using https://app.stepsecurity.io/secureworkflow/openpgpjs/openpgpjs/tests.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/tests.yml:179: update your workflow using https://app.stepsecurity.io/secureworkflow/openpgpjs/openpgpjs/tests.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/tests.yml:194: update your workflow using https://app.stepsecurity.io/secureworkflow/openpgpjs/openpgpjs/tests.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/tests.yml:195: update your workflow using https://app.stepsecurity.io/secureworkflow/openpgpjs/openpgpjs/tests.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/tests.yml:198: update your workflow using https://app.stepsecurity.io/secureworkflow/openpgpjs/openpgpjs/tests.yml/main?enable=pin
- Warn: npmCommand not pinned by hash: update_deps.sh:14
- Warn: npmCommand not pinned by hash: .github/workflows/benchmark.yml:28
- Warn: npmCommand not pinned by hash: .github/workflows/benchmark.yml:34
- Warn: npmCommand not pinned by hash: .github/workflows/sop-test-suite.yml:27
- Warn: npmCommand not pinned by hash: .github/workflows/sop-test-suite.yml:39
- Info: 0 out of 31 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 5 third-party GitHubAction dependencies pinned
- Info: 7 out of 12 npmCommand dependencies pinned
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/benchmark.yml:1
- Warn: no topLevel permission defined: .github/workflows/docs.yml:1
- Warn: no topLevel permission defined: .github/workflows/sop-test-suite.yml:1
- Warn: no topLevel permission defined: .github/workflows/tests.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 22 are checked with a SAST tool
Score
5.9
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to openpgp
@types/openpgp
TypeScript definitions for openpgp
react-native-fast-openpgp
library for use openPGP
@protontech/openpgp
OpenPGP.js is a Javascript implementation of the OpenPGP protocol. This is defined in RFC 4880.
e2e
end-to-end helps you encrypt, decrypt, digital sign, and verify signed messages within the browser using OpenPGP.