type
parameter of generateKey
: (#1179)
import { generateKey } from 'openpgp'; const { privateKey } = await generateKey({ userIDs: [{ name: 'Test', email: 'test@email' }], type: 'rsa' });
config.rejectPublicKeyAlgorithms
, and default to disallowing the use of ElGamal and DSA for encrypting new messages and signing and verifying signatures, respectively (#1264)config.minRSABits
bits (defaulting to 2048) when encrypting new messages and signing and verifying signatures, not just on key generation (#1264)openpgp.config
, you can now pass a config
to a single function call, perhaps after warning the user / confirming that they want to allow this; for example:
import { createMessage, encrypt } from 'openpgp'; const message = await createMessage('Hello world!'); try { await encrypt({ message, encryptionKeys: publicKeys }); } catch (err) { if (err.message.includes('...') && confirm('Warning: keys are insecure. Use anyway?')) { await encrypt({ message, encryptionKeys: publicKeys, config: { minRSABits: 1024, rejectPublicKeyAlgorithms: new Set() } }); } else { throw err; } }Of course, if at all possible, it's better to (ask users to) generate new keys, instead.
openpgp.HKP
has been moved to a separate package: openpgpjs/hkp-clientopenpgp.WKD
has been moved to a separate package: openpgpjs/wkd-clientopenpgp.Keyring
and LocalStore
have been removed, because keyring handling and storage should be handled in the application, as localStorage may not meet the durability requirements of the application.openpgp.createWorker
have been removed (for the rationale, please see #964)BigInt
API is not supported (see caniuse.com/bigint), and/or when the elliptic library is loaded (as it depends on bn.js).TransformStream
s aren't natively supported (see caniuse.com/transformstream).import * as openpgp from 'openpgp/lightweight';
generateKey
, support for encrypting and compressing messages is not needed, reducing the size of the build when using a build system such as webpack:
import { generateKey } from 'openpgp/lightweight';
openpgp.key.read/readArmored
with openpgp.readKey
openpgp.readKey
now takes an options object (either { armoredKey }
or { binaryKey }
){ keys: [key...], err }
objectopenpgp.readKeys
{ armoredKeys }
or { binaryKeys }
)openpgp.readPrivateKey
and openpgp.readPrivateKeys
readKey
and readKeys
, but additionally guarantee that a private key is returnedKey.prototype.encrypt/decrypt
in favor of openpgp.encryptKey/decryptKey
{ privateKey, passphrase }
)Key.prototype.decrypt
would throw when decrypting one subkey after already decrypting (and mutating) othersopenpgp.message.read/readArmored
with openpgp.readMessage
, openpgp.signature.read/readArmored
with openpgp.readSignature
, and openpgp.cleartext.readArmored
with openpgp.readCleartextMessage
openpgp.readMessage
now takes an options object (either { armoredMessage }
or { binaryMessage }
)openpgp.readSignature
now takes an options object (either { armoredSignature }
or { binarySignature }
)openpgp.readCleartextMessage
now takes an options object ({ cleartextMessage }
)openpgp.message.fromText/fromBinary
with openpgp.createMessage
, and openpgp.cleartext.fromText
with openpgp.createCleartextMessage
openpgp.createMessage
now takes an options object (either { text }
or { binary }
)openpgp.createCleartextMessage
now takes an options object ({ text }
)async
, and need to be await
ed, like all the other top-level functionsopenpgp.generateKey
, reformatKey
, and revokeKey
, return a simplified "key pair" object:
privateKey
and publicKey
properties, and no longer contains key
, privateKeyArmored
, and publicKeyArmored
format: 'armored' | 'binary' | 'object'
to determine the format of privateKey
and privateKey
(defaulting to 'armored'
)generateKey
and reformatKey
still contains a revocationCertificate
property, which is not affected by the format
optionopenpgp.encrypt
, sign
, encryptSessionKey
, encryptKey
and decryptKey
, return the result directly without wrapping it in a "results" objectpublic/privateKeys
to encryption/decryption/signing/verificationKeys
depending on their use
openpgp.encrypt
, encryptSessionKey
, and generateSessionKey
(see below), publicKeys
is now called encryptionKeys
openpgp.encrypt
and sign
, privateKeys
is now called signingKeys
openpgp.decrypt
and decryptSessionKeys
, privateKeys
is now called decryptionKeys
openpgp.decrypt
and verify
, publicKeys
is now called verificationKeys
toUserIDs
to encryptionUserIDs
and fromUserIDs
to signingUserIDs
detached
option of openpgp.encrypt
. You can separately call openpgp.sign({ message, privateKeys, detached: true })
instead (don't forget to remove the privateKeys
option from openpgp.encrypt
as well if you do so, if you don't want the message to be signed inline). However, note that storing detached signatures of plaintext data together with the encrypted data is not secureopenpgp.generateSessionKey
functionreturnSessionKey
option of openpgp.encrypt
. You can separately call openpgp.generateSessionKey({ encryptionKeys: publicKeys })
instead and call openpgp.encrypt({ sessionKey })
with the result.streaming
option of openpgp.encrypt
, decrypt
, sign
and verify
. These functions now only use streaming when a ReadableStream
or Node.js Readable
stream is passed.armor
option in openpgp.encrypt
and sign
with a format
option accepting the values 'armored'
(default), 'binary'
or 'object'
:
format: 'armored'
is equivalent to armor: true
format: 'object'
is equivalent to armor: false
format: 'binary'
returns the message serialized as a Uint8Array (this was not supported before)expectSigned
option to openpgp.encrypt
and verify
, which causes these functions to throw if there was no valid signature in the message.userId
has been changed to userID
, and keyId
has been changed to keyID
. This affects the userIDs
option of openpgp.generateKey
, the fromUserIDs
and toUserIDs
options of openpgp.encrypt
and decrypt
, Key.prototype.getKeyID
and getKeyIDs
, Message.prototype.getEncryptionKeyID
and getSigningKeyID
, etc.openpgp.enum.*.value_names
to camelCase openpgp.enum.*.valueNames
(#1093)openpgp.util
(#1175)openpgp.config.option_names
to camelCase openpgp.config.optionNames
(#1088)
openpgp.config.versionstring
to versionString
, and commentstring
to commentString
openpgp.config.ignore_mdc_error
to allowUnauthenticatedMessages
, and add a warning in the documentation that this option is insecureopenpgp.config.integrityProtect
)openpgp.config.aeadProtect
now controls whether private key encryption uses AEAD; previously this was dependent on the key version, and could only be used for v5 keysconfig
property of their options
parameter
const { privateKey } = await openpgp.generateKey({ userIDs: [{ name: 'Test', email: 'test@email' }], config: { v5Keys: true } });
openpgp.config
openpgp.packet.*
to openpgp.*Packet
openpgp.packet.Userid
to openpgp.UserIDPacket
openpgp.packet.Literal
to openpgp.LiteralDataPacket
openpgp.packet.Compressed
to openpgp.CompressedDataPacket
openpgp.packet.SymmetricallyEncrypted
to openpgp.SymmetricallyEncryptedDataPacket
openpgp.packet.SymEncryptedIntegrityProtected
to openpgp.SymEncryptedIntegrityProtectedDataPacket
openpgp.packet.SymEncryptedAEADProtected
to openpgp.AEADEncryptedDataPacket
openpgp.enums.packet.userid
to openpgp.enums.packet.userID
openpgp.enums.packet.literal
to openpgp.enums.packet.literalData
openpgp.enums.packet.compressed
to openpgp.enums.packet.compressedData
openpgp.enums.packet.symmetricallyEncrypted
to openpgp.enums.packet.symmetricallyEncryptedData
openpgp.enums.packet.symEncryptedIntegrityProtected
to openpgp.enums.packet.symEncryptedIntegrityProtectedData
openpgp.enums.packet.symEncryptedAEADProtected
to openpgp.enums.packet.aeadEncryptedData
openpgp.message.generateSessionKey
to openpgp.Message.generateSessionKey
openpgp.message.encryptSessionKey
to openpgp.Message.encryptSessionKey
v4:
import * as openpgp from 'openpgp'; const { privateKeyArmored, publicKeyArmored, revocationCertificate } = await openpgp.generateKey({ userIds: [{ name: 'Test', email: 'test@email' }] });
v5:
import { generateKey } from 'openpgp'; const { privateKey, publicKey, revocationCertificate } = await generateKey({ userIDs: [{ name: 'Test', email: 'test@email' }] });Generate a private key object
v4:
import * as openpgp from 'openpgp'; const { key } = await generateKey({ userIds: [{ name: 'Test', email: 'test@email' }] });
v5:
import { generateKey } from 'openpgp'; const { privateKey } = await generateKey({ userIDs: [{ name: 'Test', email: 'test@email' }], format: 'object' });Parse a public key (armored)
v4:
import * as openpgp from 'openpgp'; const publicKey = (await openpgp.key.readArmored(armoredKey)).keys[0];
v5:
import { readKey } from 'openpgp'; const publicKey = await readKey({ armoredKey });Parse a public key (binary)
v4:
import * as openpgp from 'openpgp'; const publicKey = (await openpgp.key.read(armoredKey)).keys[0];
v5:
import { readKey } from 'openpgp'; const publicKey = await readKey({ binaryKey });Parse one or more public keys (armored)
v4:
import * as openpgp from 'openpgp'; const publicKeys = (await openpgp.key.readArmored(armoredKeys)).keys;
v5:
import { readKeys } from 'openpgp'; const publicKeys = await readKeys({ armoredKeys });Parse and decrypt a private key (armored)
v4:
import * as openpgp from 'openpgp'; const privateKey = (await openpgp.key.readArmored(armoredKey)).keys[0]; await privateKey.decrypt(passphrase);
v5:
import { readPrivateKey, decryptKey } from 'openpgp'; const privateKey = await readPrivateKey({ armoredKey }); // Or `readKey` - `readPrivateKey` is helpful for better TypeScript type hinting. const decryptedPrivateKey = await decryptKey({ privateKey, passphrase });Encrypt and sign text message (armored output)
v4:
import * as openpgp from 'openpgp'; const message = openpgp.message.fromText(text); const encrypted = await openpgp.encrypt({ publicKeys: publicKeys, privateKeys: privateKeys, message }); console.log(encrypted.data); // String
v5:
import { createMessage, encrypt } from 'openpgp'; const message = await createMessage({ text }); const encrypted = await encrypt({ encryptionKeys: publicKeys, signingKeys: privateKeys, message }); console.log(encrypted); // StringEncrypt and sign binary message (binary output)
v4:
import * as openpgp from 'openpgp'; const message = openpgp.message.fromBinary(data); const encrypted = await openpgp.encrypt({ publicKeys: publicKeys, privateKeys: privateKeys, message, format: 'binary' }); console.log(encrypted.message.packets.write()); // Uint8Array
v5:
import { createMessage, encrypt } from 'openpgp'; const message = await createMessage({ binary: data }); const encrypted = await encrypt({ encryptionKeys: publicKeys, signingKeys: privateKeys, message, format: 'binary' }); console.log(encrypted); // Uint8ArrayEncrypt and sign message (inspect packets)
v4:
import * as openpgp from 'openpgp'; const encrypted = await openpgp.encrypt({ publicKeys: publicKeys, privateKeys: privateKeys, message, armor: false }); console.log(encrypted.message.packets); // Array
v5:
import { encrypt, readMessage } from 'openpgp'; const encrypted = await encrypt({ encryptionKeys: publicKeys, signingKeys: privateKeys, message, format: 'object' }); console.log(encrypted.packets); // ArrayDecrypt and verify text message (armored input)
v4:
import * as openpgp from 'openpgp'; const message = openpgp.message.readArmored(armoredMessage); const decrypted = await openpgp.decrypt({ privateKeys: privateKeys, publicKeys: publicKeys, message }); console.log(decrypted.data); // String console.log(decrypted.signatures[0].valid); // Boolean
v5:
import { readMessage, decrypt } from 'openpgp'; const message = await readMessage({ armoredMessage }); const decrypted = await decrypt({ decryptionKeys: privateKeys, verificationKeys: publicKeys, message }); console.log(decrypted.data); // String console.log(await decrypted.signatures[0].verified); // BooleanDecrypt and verify binary message (binary input)
v4:
import * as openpgp from 'openpgp'; const message = openpgp.message.read(binaryMessage); const decrypted = await openpgp.decrypt({ privateKeys: privateKeys, publicKeys: publicKeys, message }); console.log(decrypted.data); // String console.log(decrypted.signatures[0].valid); // Boolean
v5:
import { readMessage, decrypt } from 'openpgp'; const message = await readMessage({ binaryMessage }); const decrypted = await decrypt({ decryptionKeys: privateKeys, verificationKeys: publicKeys, message, format: 'binary' }); console.log(decrypted.data); // Uint8Array console.log(await decrypted.signatures[0].verified); // BooleanDecrypt and verify message, and throw if it's not verified
v4:
import * as openpgp from 'openpgp'; const decrypted = await openpgp.decrypt({ privateKeys: privateKeys, publicKeys: publicKeys, message }); if (!decrypted.signatures.some(signature => signature.valid)) { throw new Error("Couldn't find valid signature in message"); }
v5:
import { decrypt } from 'openpgp'; const decrypted = await decrypt({ decryptionKeys: privateKeys, verificationKeys: publicKeys, message, expectSigned: true });Sign cleartext message (armored output)
v4:
import * as openpgp from 'openpgp'; const message = openpgp.cleartext.fromText(text); const signed = await openpgp.sign({ privateKeys: privateKeys, message }); console.log(signed.data); // String
v5:
import { createCleartextMessage, sign } from 'openpgp'; const message = await createCleartextMessage({ text }); const signed = await sign({ signingKeys: privateKeys, message }); console.log(signed); // StringSign text message (binary output)
v4:
import * as openpgp from 'openpgp'; const message = openpgp.message.fromText(text); const signed = await openpgp.sign({ privateKeys: privateKeys, message, armor: false }); console.log(signed.message.packets.write()); // Uint8Array
v5:
import { createMessage, sign } from 'openpgp'; const message = await createMessage({ text }); const signed = await sign({ signingKeys: privateKeys, message, format: 'binary' }); console.log(signed); // Uint8ArrayDetached-sign cleartext message (armored output)
v4:
import * as openpgp from 'openpgp'; const message = openpgp.cleartext.fromText(text); const signed = await openpgp.sign({ privateKeys: privateKeys, message, detached: true }); console.log(signed.signature); // String
v5:
import { createMessage, sign } from 'openpgp'; const message = await createMessage({ text: util.removeTrailingSpaces(text) }); const signed = await sign({ signingKeys: privateKeys, message, detached: true }); console.log(signed); // StringDetached-sign binary message (binary output)
v4:
import * as openpgp from 'openpgp'; const message = openpgp.message.fromText(text); const signed = await openpgp.sign({ privateKeys: privateKeys, message, detached: true, armor: false }); console.log(signed.signature.packets.write()); // Uint8Array
v5:
import { createMessage, sign } from 'openpgp'; const message = await createMessage({ text }); const signed = await sign({ signingKeys: privateKeys, message, detached: true, format: 'binary' }); console.log(signed); // Uint8ArrayVerify signed text message (armored input)
v4:
import * as openpgp from 'openpgp'; const message = await openpgp.message.readArmored(armor); const verified = await openpgp.verify({ publicKeys: publicKeys, message }); console.log(openpgp.util.nativeEOL(openpgp.util.decode_utf8(verified.data))); // String console.log(verified.signatures); // Array
v5:
import { readMessage, verify } from 'openpgp'; const message = await readMessage({ armoredMessage }); const verified = await verify({ verificationKeys: publicKeys, message }); console.log(verified.data); // String console.log(verified.signatures); // ArrayVerify signed binary message (binary input)
v4:
import * as openpgp from 'openpgp'; const message = await openpgp.message.read(binary); const verified = await openpgp.verify({ publicKeys: publicKeys, message }); console.log(verified.data); // Uint8Array console.log(verified.signatures); // Array
v5:
import { readMessage, verify } from 'openpgp'; const message = await readMessage({ binaryMessage }); const verified = await verify({ verificationKeys: publicKeys, message, format: 'binary' }); console.log(verified.data); // Uint8Array console.log(verified.signatures); // ArrayEncrypt session keys (armored output)
v4:
import * as openpgp from 'openpgp'; const encrypted = await openpgp.encryptSessionKey({ publicKeys: publicKeys, data, algorithm }); console.log(encrypted.message.armor()); // String
v5:
import { encryptSessionKey } from 'openpgp'; const encrypted = await encryptSessionKey({ encryptionKeys: publicKeys, data, algorithm }); console.log(encrypted); // StringEncrypt session keys (binary output)
v4:
import * as openpgp from 'openpgp'; const encrypted = await openpgp.encryptSessionKey({ publicKeys: publicKeys, data, algorithm }); console.log(encrypted.message.packets.write()); // Uint8Array
v5:
import { encryptSessionKey } from 'openpgp'; const encrypted = await encryptSessionKey({ encryptionKeys: publicKeys, data, algorithm, format: 'binary' }); console.log(encrypted); // Uint8ArrayStreaming-encrypt text message on Node.js (armored output)
v4:
import * as openpgp from 'openpgp'; const data = fs.createReadStream(filename, { encoding: 'utf8' }); const message = openpgp.message.fromText(data); const encrypted = await openpgp.encrypt({ publicKeys: publicKeys, message }); encrypted.data.on('data', chunk => { console.log(openpgp.util.Uint8Array_to_str(chunk)); // String });
v5:
import { createMessage, encrypt } from 'openpgp'; const data = fs.createReadStream(filename, { encoding: 'utf8' }); const message = await createMessage({ text: data }); const encrypted = await encrypt({ encryptionKeys: publicKeys, message }); encrypted.on('data', chunk => { console.log(chunk); // String });Streaming-encrypt binary message on Node.js (binary output)
v4:
import * as openpgp from 'openpgp'; const data = fs.createReadStream(filename); const message = openpgp.message.fromBinary(data); const encrypted = await openpgp.encrypt({ publicKeys: publicKeys, message, armor: false }); openpgp.stream.webToNode(encrypted.message.packets.write()).pipe(targetStream);
v5:
import { createMessage, encrypt } from 'openpgp'; const data = fs.createReadStream(filename); const message = await createMessage({ binary: data }); const encrypted = await encrypt({ encryptionKeys: publicKeys, message, format: 'binary' }); encrypted.pipe(targetStream);
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4