Methods
armor(messageType, body, partIndexopt, partTotalopt, customCommentopt, emitChecksumopt, configopt) → {String|ReadableStream.<String>}
Armor an OpenPGP binary packet block
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
messageType |
module:enums.armor | Type of the message |
|
body |
Uint8Array | ReadableStream.<Uint8Array> | The message body to armor |
|
partIndex |
Integer |
<optional> |
|
partTotal |
Integer |
<optional> |
|
customComment |
String |
<optional> |
Additional comment to add to the armored string |
emitChecksum |
Boolean |
<optional> |
Whether to compute and include the CRC checksum (NB: some types of data must not include it, but compliance is left as responsibility of the caller: this function does not carry out any checks) |
config |
Object |
<optional> |
Full configuration, defaults to openpgp.config |
- Source:
Returns:
Armored text.
- Type
- String | ReadableStream.<String>
(async) createCleartextMessage(options)
Creates a new CleartextMessage object from text
Parameters:
Name | Type | Description | ||||||
---|---|---|---|---|---|---|---|---|
options |
Object |
Properties
|
- Source:
createKey(packetlist) → {Key}
Creates a PublicKey or PrivateKey depending on the packetlist in input
Parameters:
Name | Type | Description |
---|---|---|
packetlist |
PacketList | packets to parse |
- Source:
Throws:
if no key packet was found
Returns:
parsed key
- Type
- Key
(async) createMessage(options) → {Promise.<Message>}
Creates new message object from text or binary data.
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
Properties
|
- Source:
Returns:
New message object.
- Type
- Promise.<Message>
(async) decrypt(options) → {Promise.<Object>}
Decrypts a message with the user's private key, a session key or a password.
One of decryptionKeys
, sessionkeys
or passwords
must be specified (passing a combination of these options is not supported).
Parameters:
Name | Type | Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
Properties
|
- Source:
Returns:
Object containing decrypted and verified message in the form:
{
data: MaybeStream<String>, (if format was 'utf8', the default)
data: MaybeStream<Uint8Array>, (if format was 'binary')
filename: String,
signatures: [
{
keyID: module:type/keyid~KeyID,
verified: Promise<true>,
signature: Promise<Signature>
}, ...
]
}
where `signatures` contains a separate entry for each signature packet found in the input message.
- Type
- Promise.<Object>
(async) decryptKey(options) → {Promise.<PrivateKey>}
Unlock a private key with the given passphrase. This method does not change the original key.
Parameters:
Name | Type | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
Properties
|
- Source:
Returns:
The unlocked key object.
- Type
- Promise.<PrivateKey>
(async) decryptSessionKeys(options) → {Promise.<Array.<Object>>}
Decrypt symmetric session keys using private keys or passwords (not both).
One of decryptionKeys
or passwords
must be specified.
Parameters:
Name | Type | Description | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
Properties
|
- Source:
Throws:
if no session key could be found or decrypted
Returns:
Array of decrypted session key, algorithm pairs in the form: { data:Uint8Array, algorithm:String }
- Type
- Promise.<Array.<Object>>
(async) encrypt(options) → {Promise.<(MaybeStream.<String>|MaybeStream.<Uint8Array>)>}
Encrypts a message using public keys, passwords or both at once. At least one of encryptionKeys
, passwords
or sessionKeys
must be specified. If signing keys are specified, those will be used to sign the message.
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
Properties
|
- Source:
Returns:
Encrypted message (string if armor
was true, the default; Uint8Array if armor
was false).
- Type
- Promise.<(MaybeStream.<String>|MaybeStream.<Uint8Array>)>
(async) encryptKey(options) → {Promise.<PrivateKey>}
Lock a private key with the given passphrase. This method does not change the original key.
Parameters:
Name | Type | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
Properties
|
- Source:
Returns:
The locked key object.
- Type
- Promise.<PrivateKey>
(async) encryptSessionKey(options) → {Promise.<(String|Uint8Array)>}
Encrypt a symmetric session key with public keys, passwords, or both at once.
At least one of encryptionKeys
or passwords
must be specified.
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
Properties
|
- Source:
Returns:
Encrypted session keys (string if armor
was true, the default; Uint8Array if armor
was false).
- Type
- Promise.<(String|Uint8Array)>
formatObject(object, format, config) → {String|Uint8Array|Object}
Convert the object to the given format
Parameters:
Name | Type | Description |
---|---|---|
object |
Key | Message | |
format |
'armored' | 'binary' | 'object' | |
config |
Object | Full configuration |
- Source:
Returns:
- Type
- String | Uint8Array | Object
(async) generateKey(options) → {Promise.<Object>}
Generates a new OpenPGP key pair. Supports RSA and ECC keys, as well as the newer Curve448 and Curve25519 keys. By default, primary and subkeys will be of same type. The generated primary key will have signing capabilities. By default, one subkey with encryption capabilities is also generated.
Parameters:
Name | Type | Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
Properties
|
- Source:
Returns:
The generated key object in the form: { privateKey:PrivateKey|Uint8Array|String, publicKey:PublicKey|Uint8Array|String, revocationCertificate:String }
- Type
- Promise.<Object>
(async) generateSessionKey(options) → {Promise.<{data: Uint8Array, algorithm: String}>}
Generate a new session key object, taking the algorithm preferences of the passed public keys into account, if any.
Parameters:
Name | Type | Description | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
Properties
|
- Source:
Returns:
Object with session key data and algorithm.
- Type
- Promise.<{data: Uint8Array, algorithm: String}>
getCipherBlockSize(algo)
Get block size for given cipher algo
Parameters:
Name | Type | Description |
---|---|---|
algo |
module:enums.symmetric | alrogithm identifier |
- Source:
getCipherKeySize(algo)
Get key size for given cipher algo
Parameters:
Name | Type | Description |
---|---|---|
algo |
module:enums.symmetric | alrogithm identifier |
- Source:
getCipherParams(algo)
Get block and key size for given cipher algo
Parameters:
Name | Type | Description |
---|---|---|
algo |
module:enums.symmetric | alrogithm identifier |
- Source:
getCompressionStreamInstantiators(compressionFormat) → {Object}
Get Compression Stream API instatiators if the constructors are implemented.
NB: the return instatiator functions will throw when called if the provided compressionFormat
is not supported
(supported formats cannot be determined in advance).
Parameters:
Name | Type | Description |
---|---|---|
compressionFormat |
'deflate-raw' | 'deflate' | 'gzip' | string |
- Source:
Returns:
- Type
- Object
newPacketFromTag(tag, allowedPackets) → {Object}
Instantiate a new packet given its tag
Parameters:
Name | Type | Description |
---|---|---|
tag |
module:enums.packet | Property value from module:enums.packet |
allowedPackets |
Object | mapping where keys are allowed packet tags, pointing to their Packet class |
- Source:
Throws:
-
for disallowed or unknown packets
- Type
- Error | UnsupportedError
Returns:
New packet object with type based on tag
- Type
- Object
newS2KFromConfig() → {Object}
Instantiate a new S2K instance based on the config settings
- Source:
Throws:
-
for unknown or unsupported types
- Type
- Error
Returns:
New s2k object
- Type
- Object
newS2KFromType(type) → {Object}
Instantiate a new S2K instance of the given type
Parameters:
Name | Type | Description |
---|---|---|
type |
module:enums.s2k |
- Source:
Throws:
-
for unknown or unsupported types
- Type
- Error
Returns:
New s2k object
- Type
- Object
(async) produceEncryptionKey(keyVersion, s2k, passphrase, cipherAlgo, aeadModeopt, serializedPacketTagopt, isLegacyAEADopt)
Derive encryption key
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
keyVersion |
Number | key derivation differs for v5 keys |
|
s2k |
module:type/s2k | ||
passphrase |
String | ||
cipherAlgo |
module:enums.symmetric | ||
aeadMode |
module:enums.aead |
<optional> |
for AEAD-encrypted keys only (excluding v5) |
serializedPacketTag |
Uint8Array |
<optional> |
for AEAD-encrypted keys only (excluding v5) |
isLegacyAEAD |
Boolean |
<optional> |
for AEAD-encrypted keys from RFC4880bis (v4 and v5 only) |
- Source:
Returns:
encryption key
(async) readCleartextMessage(options) → {Promise.<CleartextMessage>}
Reads an OpenPGP cleartext signed message and returns a CleartextMessage object
Parameters:
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
Properties
|
- Source:
Returns:
New cleartext message object.
- Type
- Promise.<CleartextMessage>
(async) readKey(options) → {Promise.<Key>}
Reads an (optionally armored) OpenPGP key and returns a key object
Parameters:
Name | Type | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
Properties
|
- Source:
Returns:
Key object.
- Type
- Promise.<Key>
(async) readKeys(options) → {Promise.<Array.<Key>>}
Reads an (optionally armored) OpenPGP key block and returns a list of key objects
Parameters:
Name | Type | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
Properties
|
- Source:
Returns:
Key objects.
- Type
- Promise.<Array.<Key>>
(async) readMessage(options) → {Promise.<Message>}
Reads an (optionally armored) OpenPGP message and returns a Message object
Parameters:
Name | Type | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
Properties
|
- Source:
Returns:
New message object.
- Type
- Promise.<Message>
(async) readPrivateKey(options) → {Promise.<PrivateKey>}
Reads an (optionally armored) OpenPGP private key and returns a PrivateKey object
Parameters:
Name | Type | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
Properties
|
- Source:
Returns:
Key object.
- Type
- Promise.<PrivateKey>
(async) readPrivateKeys(options) → {Promise.<Array.<PrivateKey>>}
Reads an (optionally armored) OpenPGP private key block and returns a list of PrivateKey objects
Parameters:
Name | Type | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
Properties
|
- Source:
Returns:
Key objects.
- Type
- Promise.<Array.<PrivateKey>>
(async) readSignature(options) → {Promise.<Signature>}
reads an (optionally armored) OpenPGP signature and returns a signature object
Parameters:
Name | Type | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
Properties
|
- Source:
Returns:
New signature object.
- Type
- Promise.<Signature>
(async) reformatKey(options) → {Promise.<Object>}
Reformats signature packets for a key and rewraps key object.
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
Properties
|
- Source:
Returns:
The generated key object in the form: { privateKey:PrivateKey|Uint8Array|String, publicKey:PublicKey|Uint8Array|String, revocationCertificate:String }
- Type
- Promise.<Object>
(async) revokeKey(options) → {Promise.<Object>}
Revokes a key. Requires either a private key or a revocation certificate. If a revocation certificate is passed, the reasonForRevocation parameter will be ignored.
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
Properties
|
- Source:
Returns:
The revoked key in the form: { privateKey:PrivateKey|Uint8Array|String, publicKey:PublicKey|Uint8Array|String } if private key is passed, or { privateKey: null, publicKey:PublicKey|Uint8Array|String } otherwise
- Type
- Promise.<Object>
(async) runAEAD(fn, key, data) → {Promise.<(Uint8Array|ReadableStream.<Uint8Array>)>}
En/decrypt the payload.
Parameters:
Name | Type | Description |
---|---|---|
fn |
encrypt | decrypt | Whether to encrypt or decrypt |
key |
Uint8Array | The session key used to en/decrypt the payload |
data |
Uint8Array | ReadableStream.<Uint8Array> | The data to en/decrypt |
Returns:
- Type
- Promise.<(Uint8Array|ReadableStream.<Uint8Array>)>
(async) sign(options) → {Promise.<MaybeStream.<(String|Uint8Array)>>}
Signs a message.
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
Properties
|
- Source:
Returns:
Signed message (string if armor
was true, the default; Uint8Array if armor
was false).
- Type
- Promise.<MaybeStream.<(String|Uint8Array)>>
(async) unarmor(input) → {Promise.<Object>}
Dearmor an OpenPGP armored message; verify the checksum and return the encoded bytes
Parameters:
Name | Type | Description |
---|---|---|
input |
String | OpenPGP armored message |
- Source:
Returns:
An object with attribute "text" containing the message text, an attribute "data" containing a stream of bytes and "type" for the ASCII armor type
- Type
- Promise.<Object>
(async) verify(options) → {Promise.<Object>}
Verifies signatures of cleartext signed message
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
Properties
|
- Source:
Returns:
Object containing verified message in the form:
{
data: MaybeStream<String>, (if `message` was a CleartextMessage)
data: MaybeStream<Uint8Array>, (if `message` was a Message)
signatures: [
{
keyID: module:type/keyid~KeyID,
verified: Promise<true>,
signature: Promise<Signature>
}, ...
]
}
where `signatures` contains a separate entry for each signature packet found in the input message.
- Type
- Promise.<Object>
(async) wrapKeyObject(secretKeyPacket, secretSubkeyPackets, options, config) → {PrivateKey}
Construct PrivateKey object from the given key packets, add certification signatures and set passphrase protection The new key includes a revocation certificate that must be removed before returning the key, otherwise the key is considered revoked.
Parameters:
Name | Type | Description |
---|---|---|
secretKeyPacket |
SecretKeyPacket | |
secretSubkeyPackets |
SecretSubkeyPacket | |
options |
Object | |
config |
Object | Full configuration |
- Source:
Returns:
- Type
- PrivateKey
zlib(compressionStreamInstantiator, ZlibStreamedConstructor) → {ReadableStream.<Uint8Array>}
Zlib processor relying on Compression Stream API if available, or falling back to fflate otherwise.
Parameters:
Name | Type | Description |
---|---|---|
compressionStreamInstantiator |
function | |
ZlibStreamedConstructor |
FunctionConstructor | fflate constructor |
- Source:
Returns:
compressed or decompressed data
- Type
- ReadableStream.<Uint8Array>