Class: Message

Message(packetlist)

Class that represents an OpenPGP message. Can be an encrypted message, signed message, compressed message or literal message See https://tools.ietf.org/html/rfc4880#section-11.3

Constructor

new Message(packetlist)

Parameters:
Name Type Description
packetlist PacketList

The packets that form this message

Source:

Classes

Message

Methods

(async, static) encryptSessionKey(sessionKey, algorithm, aeadAlgorithm, publicKeys, passwords, wildcard, encryptionKeyIds, date, userIds, config) → {Promise.<Message>}

Encrypt a session key either with public keys, passwords, or both at once.

Parameters:
Name Type Default Description
sessionKey Uint8Array

session key for encryption

algorithm String

session key algorithm

aeadAlgorithm String

(optional) aead algorithm, e.g. 'eax' or 'ocb'

publicKeys Array.<Key>

(optional) public key(s) for message encryption

passwords Array.<String>

(optional) for message encryption

wildcard Boolean false

(optional) use a key ID of 0 instead of the public key IDs

encryptionKeyIds Array.<module:type/keyid~Keyid>

(optional) array of key IDs to use for encryption. Each encryptionKeyIds[i] corresponds to publicKeys[i]

date Date

(optional) override the date

userIds Array

(optional) user IDs to encrypt for, e.g. [{ name:'Robert Receiver', email:'robert@openpgp.org' }]

config Object

(optional) full configuration, defaults to openpgp.config

Source:
Returns:

new message with encrypted content

Type
Promise.<Message>

(static) fromBinary(bytes, filename, date, type) → {Message}

creates new message object from binary data

Parameters:
Name Type Default Description
bytes Uint8Array | ReadableStream.<Uint8Array>
filename String

(optional)

date Date

(optional)

type utf8 | binary | text | mime binary

(optional) data packet type

Source:
Returns:

new message object

Type
Message

(static) fromText(text, filename, date, type) → {Message}

creates new message object from text

Parameters:
Name Type Default Description
text String | ReadableStream.<String>
filename String

(optional)

date Date

(optional)

type utf8 | binary | text | mime utf8

(optional) data packet type

Source:
Returns:

new message object

Type
Message

(async, static) generateSessionKey(keys, date, userIds, config) → {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
keys Array.<Key>

(optional) public key(s) to select algorithm preferences for

date Date

(optional) date to select algorithm preferences at

userIds Array.<Object>

(optional) user IDs to select algorithm preferences for

config Object

(optional) full configuration, defaults to openpgp.config

Source:
Returns:

object with session key data and algorithm

Type
Promise.<{data: Uint8Array, algorithm: String}>

(async) appendSignature(detachedSignature)

Append signature to unencrypted message object

Parameters:
Name Type Description
detachedSignature String | Uint8Array

The detached ASCII-armored or Uint8Array PGP signature

Source:

armor(config) → {ReadableStream.<String>}

Returns ASCII armored text of message

Parameters:
Name Type Description
config Object

(optional) full configuration, defaults to openpgp.config

Source:
Returns:

ASCII armor

Type
ReadableStream.<String>

compress(config) → {Message}

Compresses the message (the literal and -if signed- signature data packets of the message)

Parameters:
Name Type Description
config Object

(optional) full configuration, defaults to openpgp.config

Source:
Returns:

new message with compressed content

Type
Message

(async) decrypt(privateKeys, passwords, sessionKeys, streaming, config) → {Promise.<Message>}

Decrypt the message. Either a private key, a session key, or a password must be specified.

Parameters:
Name Type Description
privateKeys Array.<Key>

(optional) private keys with decrypted secret data

passwords Array.<String>

(optional) passwords used to decrypt

sessionKeys Array.<Object>

(optional) session keys in the form: { data:Uint8Array, algorithm:String, [aeadAlgorithm:String] }

streaming Boolean

(optional) whether to process data as a stream

config Object

(optional) full configuration, defaults to openpgp.config

Source:
Returns:

new message with decrypted content

Type
Promise.<Message>

(async) decryptSessionKeys(privateKeys, passwords, config) → {Promise.<Array.<{data: Uint8Array, algorithm: String}>>}

Decrypt encrypted session keys either with private keys or passwords.

Parameters:
Name Type Description
privateKeys Array.<Key>

(optional) private keys with decrypted secret data

passwords Array.<String>

(optional) passwords used to decrypt

config Object

(optional) full configuration, defaults to openpgp.config

Source:
Returns:

array of object with potential sessionKey, algorithm pairs

Type
Promise.<Array.<{data: Uint8Array, algorithm: String}>>

(async) encrypt(keys, passwords, sessionKey, wildcard, encryptionKeyIds, date, userIds, streaming, config) → {Promise.<Message>}

Encrypt the message either with public keys, passwords, or both at once.

Parameters:
Name Type Default Description
keys Array.<Key>

(optional) public key(s) for message encryption

passwords Array.<String>

(optional) password(s) for message encryption

sessionKey Object

(optional) session key in the form: { data:Uint8Array, algorithm:String, [aeadAlgorithm:String] }

wildcard Boolean false

(optional) use a key ID of 0 instead of the public key IDs

encryptionKeyIds Array.<module:type/keyid~Keyid>

(optional) array of key IDs to use for encryption. Each encryptionKeyIds[i] corresponds to publicKeys[i]

date Date

(optional) override the creation date of the literal package

userIds Array.<Object>

(optional) user IDs to encrypt for, e.g. [{ name:'Robert Receiver', email:'robert@openpgp.org' }]

streaming Boolean

(optional) whether to process data as a stream

config Object

(optional) full configuration, defaults to openpgp.config

Source:
Returns:

new message with encrypted content

Type
Promise.<Message>

getEncryptionKeyIds() → {Array.<module:type/keyid~Keyid>}

Returns the key IDs of the keys to which the session key is encrypted

Source:
Returns:

array of keyid objects

Type
Array.<module:type/keyid~Keyid>

getFilename() → {String|null}

Get filename from literal data packet

Source:
Returns:

filename of literal data packet as string

Type
String | null

getLiteralData() → {Uint8Array|null}

Get literal data that is the body of the message

Source:
Returns:

literal body of the message as Uint8Array

Type
Uint8Array | null

getSigningKeyIds() → {Array.<module:type/keyid~Keyid>}

Returns the key IDs of the keys that signed the message

Source:
Returns:

array of keyid objects

Type
Array.<module:type/keyid~Keyid>

getText() → {String|null}

Get literal data as text

Source:
Returns:

literal body of the message interpreted as text

Type
String | null

(async) sign(privateKeys, signature, signingKeyIds, date, userIds, streaming, config) → {Promise.<Message>}

Sign the message (the literal data packet of the message)

Parameters:
Name Type Default Description
privateKeys Array.<Key>

private keys with decrypted secret key data for signing

signature Signature null

(optional) any existing detached signature to add to the message

signingKeyIds Array.<module:type/keyid~Keyid>

(optional) array of key IDs to use for signing. Each signingKeyIds[i] corresponds to privateKeys[i]

date Date

(optional) override the creation time of the signature

userIds Array

(optional) user IDs to sign with, e.g. [{ name:'Steve Sender', email:'steve@openpgp.org' }]

streaming Boolean false

(optional) whether to process data as a stream

config Object

(optional) full configuration, defaults to openpgp.config

Source:
Returns:

new message with signed content

Type
Promise.<Message>

(async) signDetached(privateKeys, signature, signingKeyIds, date, userIds, streaming, config) → {Promise.<Signature>}

Create a detached signature for the message (the literal data packet of the message)

Parameters:
Name Type Default Description
privateKeys Array.<Key>

private keys with decrypted secret key data for signing

signature Signature null

(optional) any existing detached signature

signingKeyIds Array.<module:type/keyid~Keyid>

(optional) array of key IDs to use for signing. Each signingKeyIds[i] corresponds to privateKeys[i]

date Date

(optional) override the creation time of the signature

userIds Array

(optional) user IDs to sign with, e.g. [{ name:'Steve Sender', email:'steve@openpgp.org' }]

streaming Boolean false

(optional) whether to process data as a stream

config Object

(optional) full configuration, defaults to openpgp.config

Source:
Returns:

new detached signature of message content

Type
Promise.<Signature>

unwrapCompressed() → {Message}

Unwrap compressed message

Source:
Returns:

message Content of compressed message

Type
Message

(async) verify(keys, date, streaming, config) → {Promise.<Array.<({keyid: module:type/keyid~Keyid, valid: Boolean})>>}

Verify message signatures

Parameters:
Name Type Description
keys Array.<Key>

array of keys to verify signatures

date Date

(optional) Verify the signature against the given date, i.e. check signature creation time < date < expiration time

streaming Boolean

(optional) whether to process data as a stream

config Object

(optional) full configuration, defaults to openpgp.config

Source:
Returns:

list of signer's keyid and validity of signature

Type
Promise.<Array.<({keyid: module:type/keyid~Keyid, valid: Boolean})>>

(async) verifyDetached(keys, signature, date, config) → {Promise.<Array.<({keyid: module:type/keyid~Keyid, valid: Boolean})>>}

Verify detached message signature

Parameters:
Name Type Description
keys Array.<Key>

array of keys to verify signatures

signature Signature
date Date

Verify the signature against the given date, i.e. check signature creation time < date < expiration time

config Object

(optional) full configuration, defaults to openpgp.config

Source:
Returns:

list of signer's keyid and validity of signature

Type
Promise.<Array.<({keyid: module:type/keyid~Keyid, valid: Boolean})>>

write() → {ReadableStream.<Uint8Array>}

Returns binary encoded message

Source:
Returns:

binary message

Type
ReadableStream.<Uint8Array>