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, aeadAlgorithmopt, publicKeysopt, passwordsopt, wildcardopt, encryptionKeyIdsopt, dateopt, userIdsopt, configopt) → {Message}

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

Parameters:
Name Type Attributes 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 <optional>
false

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:'[email protected]' }]

config Object <optional>

Full configuration, defaults to openpgp.config

Source:
Returns:

New message with encrypted content.

Type
Message

(static) fromBinary(bytes, filenameopt, dateopt, typeopt) → {Message}

Creates new message object from binary data.

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

The message contents

filename String <optional>
""

Name of the file (if any)

date Date <optional>
current date

Date of the message, or modification date of the file

type 'utf8' | 'binary' | 'text' | 'mime' <optional>
'binary'

Data packet type

Source:
Returns:

New message object.

Type
Message

(static) fromText(text, filenameopt, dateopt, typeopt) → {Message}

Creates new message object from text.

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

The message contents

filename String <optional>
""

Name of the file (if any)

date Date <optional>
current date

Date of the message, or modification date of the file

type 'utf8' | 'binary' | 'text' | 'mime' <optional>
'utf8'

Data packet type

Source:
Returns:

New message object.

Type
Message

(async, static) generateSessionKey(keysopt, dateopt, userIdsopt, configopt) → {Object}

Generate a new session key object, taking the algorithm preferences of the passed public keys into account, if any.

Parameters:
Name Type Attributes 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
Object

(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(configopt) → {ReadableStream.<String>}

Returns ASCII armored text of message

Parameters:
Name Type Attributes Description
config Object <optional>

Full configuration, defaults to openpgp.config

Source:
Returns:

ASCII armor.

Type
ReadableStream.<String>

compress(configopt) → {Message}

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

Parameters:
Name Type Attributes Description
config Object <optional>

Full configuration, defaults to openpgp.config

Source:
Returns:

New message with compressed content.

Type
Message

(async) decrypt(privateKeysopt, passwordsopt, sessionKeysopt, streamingopt, configopt) → {Message}

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

Parameters:
Name Type Attributes 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
Message

(async) decryptSessionKeys(privateKeysopt, passwordsopt, configopt) → {Promise.<Array.<{data: Uint8Array, algorithm: String}>>}

Decrypt encrypted session keys either with private keys or passwords.

Parameters:
Name Type Attributes 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(keysopt, passwordsopt, sessionKeyopt, wildcardopt, encryptionKeyIdsopt, dateopt, userIdsopt, streamingopt, configopt) → {Message}

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

Parameters:
Name Type Attributes 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 <optional>
false

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:'[email protected]' }]

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
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, signatureopt, signingKeyIdsopt, dateopt, userIdsopt, streamingopt, configopt) → {Message}

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

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

private keys with decrypted secret key data for signing

signature Signature <optional>
null

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:'[email protected]' }]

streaming Boolean <optional>
false

Whether to process data as a stream

config Object <optional>

Full configuration, defaults to openpgp.config

Source:
Returns:

New message with signed content.

Type
Message

(async) signDetached(privateKeys, signatureopt, signingKeyIdsopt, dateopt, userIdsopt, streamingopt, configopt) → {Signature}

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

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

private keys with decrypted secret key data for signing

signature Signature <optional>
null

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:'[email protected]' }]

streaming Boolean <optional>
false

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
Signature

unwrapCompressed() → {Message}

Unwrap compressed message

Source:
Returns:

Message Content of compressed message.

Type
Message

(async) verify(keys, dateopt, streamingopt, configopt) → {Array.<({keyid: module:type/keyid~Keyid, valid: Boolean})>}

Verify message signatures

Parameters:
Name Type Attributes 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
Array.<({keyid: module:type/keyid~Keyid, valid: Boolean})>

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

Verify detached message signature

Parameters:
Name Type Attributes 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
Array.<({keyid: module:type/keyid~Keyid, valid: Boolean})>

write() → {ReadableStream.<Uint8Array>}

Returns binary encoded message

Source:
Returns:

Binary message.

Type
ReadableStream.<Uint8Array>