Methods
armor(messageType, body, partIndexopt, partTotalopt, customCommentopt) → {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 |
- 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
or passwords
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. 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.
Parameters:
Name | Type | Description | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
Properties
|
- Source:
Returns:
Object with session key data and algorithm.
- Type
- Promise.<{data: Uint8Array, algorithm: String}>
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
(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) 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