Global

Methods

armor(messagetype, body, partindex, parttotal, customComment) → {String|ReadableStream.<String>}

Armor an OpenPGP binary packet block

Parameters:
Name Type Description
messagetype Integer

type of the message

body
partindex Integer
parttotal Integer
customComment String

(optional) additional comment to add to the armored string

Source:
Returns:

Armored text

Type
String | ReadableStream.<String>

(async) decrypt(message, privateKeys, passwords, sessionKeys, publicKeys, format, streaming, signature, date, config) → {Promise.<Object>}

Decrypts a message with the user's private key, a session key or a password. Either a private key, a session key or a password must be specified.

Parameters:
Name Type Description
message Message

the message object with the encrypted data

privateKeys Key | Array.<Key>

(optional) private keys with decrypted secret key data or session key

passwords String | Array.<String>

(optional) passwords to decrypt the message

sessionKeys Object | Array.<Object>

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

publicKeys Key | Array.<Key>

(optional) array of public keys or single key, to verify signatures

format 'utf8' | 'binary'

(optional) whether to return data as a string(Stream) or Uint8Array(Stream). If 'utf8' (the default), also normalize newlines.

streaming 'web' | 'ponyfill' | 'node' | false

(optional) whether to return data as a stream. Defaults to the type of stream message was created from, if any.

signature Signature

(optional) detached signature for verification

date Date

(optional) use the given date for verification instead of the current time

config Object

(optional) custom configuration settings to overwrite those in openpgp.config

Source:
Returns:

Object containing decrypted and verified message in the form:

{
  data: String|ReadableStream<String>|NodeStream, (if format was 'utf8', the default)
  data: Uint8Array|ReadableStream<Uint8Array>|NodeStream, (if format was 'binary')
  filename: String,
  signatures: [
    {
      keyid: module:type/keyid~Keyid,
      verified: Promise<Boolean>,
      valid: Boolean (if streaming was false)
    }, ...
  ]
}
Type
Promise.<Object>

(async) decryptKey(privateKey, passphrase, config) → {Promise.<Key>}

Unlock a private key with the given passphrase. This method does not change the original key.

Parameters:
Name Type Description
privateKey Key

the private key to decrypt

passphrase String | Array.<String>

the user's passphrase(s)

config Object

(optional) custom configuration settings to overwrite those in openpgp.config

Source:
Returns:

the unlocked key object

Type
Promise.<Key>

(async) decryptSessionKeys(message, privateKeys, passwords, config) → {Promise.<(Object|undefined)>}

Decrypt symmetric session keys with a private key or password. Either a private key or a password must be specified.

Parameters:
Name Type Description
message Message

a message object containing the encrypted session key packets

privateKeys Key | Array.<Key>

(optional) private keys with decrypted secret key data

passwords String | Array.<String>

(optional) passwords to decrypt the session key

config Object

(optional) custom configuration settings to overwrite those in openpgp.config

Source:
Returns:

Array of decrypted session key, algorithm pairs in form: { data:Uint8Array, algorithm:String } or 'undefined' if no key packets found

Type
Promise.<(Object|undefined)>

(async) encrypt(message, publicKeys, privateKeys, passwords, sessionKey, armor, streaming, signature, wildcard, signingKeyIds, encryptionKeyIds, date, fromUserIds, toUserIds, config) → {Promise.<(String|ReadableStream.<String>|NodeStream.<String>|Uint8Array|ReadableStream.<Uint8Array>|NodeStream.<Uint8Array>)>}

Encrypts message text/data with public keys, passwords or both at once. At least either public keys or passwords must be specified. If private keys are specified, those will be used to sign the message.

Parameters:
Name Type Description
message Message

message to be encrypted as created by openpgp.Message.fromText or openpgp.Message.fromBinary

publicKeys Key | Array.<Key>

(optional) array of keys or single key, used to encrypt the message

privateKeys Key | Array.<Key>

(optional) private keys for signing. If omitted message will not be signed

passwords String | Array.<String>

(optional) array of passwords or a single password to encrypt the message

sessionKey Object

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

armor Boolean

(optional) whether the return values should be ascii armored (true, the default) or binary (false)

streaming 'web' | 'ponyfill' | 'node' | false

(optional) whether to return data as a stream. Defaults to the type of stream message was created from, if any.

signature Signature

(optional) a detached signature to add to the encrypted message

wildcard Boolean

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

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

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

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 message signature

fromUserIds Array.<Object>

(optional) array of user IDs to sign with, one per key in privateKeys, e.g. [{ name:'Steve Sender', email:'steve@openpgp.org' }]

toUserIds Array.<Object>

(optional) array of user IDs to encrypt for, one per key in publicKeys, e.g. [{ name:'Robert Receiver', email:'robert@openpgp.org' }]

config Object

(optional) custom configuration settings to overwrite those in openpgp.config

Source:
Returns:

(String if armor was true, the default; Uint8Array if armor was false)

Type
Promise.<(String|ReadableStream.<String>|NodeStream.<String>|Uint8Array|ReadableStream.<Uint8Array>|NodeStream.<Uint8Array>)>

(async) encryptKey(privateKey, passphrase, config) → {Promise.<Key>}

Lock a private key with the given passphrase. This method does not change the original key.

Parameters:
Name Type Description
privateKey Key

the private key to encrypt

passphrase String | Array.<String>

if multiple passphrases, they should be in the same order as the packets each should encrypt

config Object

(optional) custom configuration settings to overwrite those in openpgp.config

Source:
Returns:

the locked key object

Type
Promise.<Key>

(async) encryptSessionKey(data, algorithm, aeadAlgorithm, publicKeys, passwords, armor, wildcard, encryptionKeyIds, date, toUserIds, config) → {Promise.<(String|Uint8Array)>}

Encrypt a symmetric session key with public keys, passwords, or both at once. At least either public keys or passwords must be specified.

Parameters:
Name Type Description
data Uint8Array

the session key to be encrypted e.g. 16 random bytes (for aes128)

algorithm String

algorithm of the symmetric session key e.g. 'aes128' or 'aes256'

aeadAlgorithm String

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

publicKeys Key | Array.<Key>

(optional) array of public keys or single key, used to encrypt the key

passwords String | Array.<String>

(optional) passwords for the message

armor Boolean

(optional) whether the return values should be ascii armored (true, the default) or binary (false)

wildcard Boolean

(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

toUserIds Array

(optional) array of user IDs to encrypt for, one per key in publicKeys, e.g. [{ name:'Phil Zimmermann', email:'phil@openpgp.org' }]

config Object

(optional) custom configuration settings to overwrite those in openpgp.config

Source:
Returns:

(String if armor was true, the default; Uint8Array if armor was false)

Type
Promise.<(String|Uint8Array)>

(async) generateKey(type, userIds, passphrase, rsaBits, curve, date, keyExpirationTime, subkeys, config) → {Promise.<Object>}

Generates a new OpenPGP key pair. Supports RSA and ECC keys. By default, primary and subkeys will be of same type.

Parameters:
Name Type Description
type ecc | rsa

(optional) The primary key algorithm type: ECC (default) or RSA

userIds Object | Array.<Object>

User IDs as objects: { name:'Jo Doe', email:'info@jo.com' }

passphrase String

(optional) The passphrase used to encrypt the resulting private key

rsaBits Number

(optional) Number of bits for RSA keys, defaults to 4096

curve String

(optional) Elliptic curve for ECC keys: curve25519 (default), p256, p384, p521, secp256k1, brainpoolP256r1, brainpoolP384r1, or brainpoolP512r1

date Date

(optional) Override the creation date of the key and the key signatures

keyExpirationTime Number

(optional) Number of seconds from the key creation time after which the key expires

subkeys Array.<Object>

(optional) Options for each subkey, default to main key options. e.g. [{sign: true, passphrase: '123'}] sign parameter defaults to false, and indicates whether the subkey should sign rather than encrypt

config Object

(optional) custom configuration settings to overwrite those in openpgp.config

Source:
Returns:

The generated key object in the form: { key:Key, privateKeyArmored:String, publicKeyArmored:String, revocationCertificate:String }

Type
Promise.<Object>

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

array of public keys or single key used to select algorithm preferences for

date Date

(optional) date to select algorithm preferences at

toUserIds Array

(optional) user IDs to select algorithm preferences for

config Object

(optional) custom configuration settings to overwrite those in openpgp.config

Source:
Returns:

object with session key data and algorithm

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

(async) readCleartextMessage(cleartextMessage, config) → {CleartextMessage}

Reads an OpenPGP cleartext signed message and returns a CleartextMessage object

Parameters:
Name Type Description
cleartextMessage String | ReadableStream.<String>

text to be parsed

config Object

(optional) custom configuration settings to overwrite those in openpgp.config

Source:
Returns:

new cleartext message object

Type
CleartextMessage

(async) readKey(armoredKey, binaryKey, config) → {Promise.<Key>}

Reads an (optionally armored) OpenPGP key and returns a key object

Parameters:
Name Type Description
armoredKey String

armored key to be parsed

binaryKey Uint8Array

binary key to be parsed

config Object

(optional) custom configuration settings to overwrite those in openpgp.config

Source:
Returns:

key object

Type
Promise.<Key>

(async) readKeys(armoredKeys, binaryKeys, config) → {Promise.<Array.<Key>>}

Reads an (optionally armored) OpenPGP key block and returns a list of key objects

Parameters:
Name Type Description
armoredKeys String | ReadableStream.<String>

armored keys to be parsed

binaryKeys Uint8Array | ReadableStream.<Uint8Array>

binary keys to be parsed

config Object

(optional) custom configuration settings to overwrite those in openpgp.config

Source:
Returns:

key objects

Type
Promise.<Array.<Key>>

(async) readMessage(armoredMessage, binaryMessage, config) → {Promise.<Message>}

Reads an (optionally armored) OpenPGP message and returns a Message object

Parameters:
Name Type Description
armoredMessage String | ReadableStream.<String>

armored message to be parsed

binaryMessage Uint8Array | ReadableStream.<Uint8Array>

binary to be parsed

config Object

(optional) custom configuration settings to overwrite those in openpgp.config

Source:
Returns:

new message object

Type
Promise.<Message>

(async) readSignature(armoredSignature, binarySignature, config) → {Signature}

reads an (optionally armored) OpenPGP signature and returns a signature object

Parameters:
Name Type Description
armoredSignature String | ReadableStream.<String>

armored signature to be parsed

binarySignature Uint8Array | ReadableStream.<Uint8Array>

binary signature to be parsed

config Object

(optional) custom configuration settings to overwrite those in openpgp.config

Source:
Returns:

new signature object

Type
Signature

(async) reformatKey(privateKey, userIds, passphrase, keyExpirationTime, config) → {Promise.<Object>}

Reformats signature packets for a key and rewraps key object.

Parameters:
Name Type Description
privateKey Key

Private key to reformat

userIds Object | Array.<Object>

User IDs as objects: { name:'Jo Doe', email:'info@jo.com' }

passphrase String

(optional) The passphrase used to encrypt the resulting private key

keyExpirationTime Number

(optional) Number of seconds from the key creation time after which the key expires

config Object

(optional) custom configuration settings to overwrite those in openpgp.config

Source:
Returns:

The generated key object in the form: { key:Key, privateKeyArmored:String, publicKeyArmored:String, revocationCertificate:String }

Type
Promise.<Object>

(async) revokeKey(key, revocationCertificate, reasonForRevocation, config) → {Promise.<Object>}

Revokes a key. Requires either a private key or a revocation certificate. If a revocation certificate is passed, the reasonForRevocation parameters will be ignored.

Parameters:
Name Type Description
key Key

(optional) public or private key to revoke

revocationCertificate String

(optional) revocation certificate to revoke the key with

reasonForRevocation Object

(optional) object indicating the reason for revocation

Properties
Name Type Description
flag module:enums.reasonForRevocation

(optional) flag indicating the reason for revocation

string String

(optional) string explaining the reason for revocation

config Object

(optional) custom configuration settings to overwrite those in openpgp.config

Source:
Returns:

The revoked key object in the form: { privateKey:Key, privateKeyArmored:String, publicKey:Key, publicKeyArmored:String } (if private key is passed) or { publicKey:Key, publicKeyArmored:String } (otherwise)

Type
Promise.<Object>

(async) sign(message, privateKeys, armor, streaming, detached, signingKeyIds, date, fromUserIds, config) → {Promise.<(String|ReadableStream.<String>|NodeStream.<String>|Uint8Array|ReadableStream.<Uint8Array>|NodeStream.<Uint8Array>)>}

Signs a message.

Parameters:
Name Type Description
message CleartextMessage | Message

(cleartext) message to be signed

privateKeys Key | Array.<Key>

array of keys or single key with decrypted secret key data to sign cleartext

armor Boolean

(optional) whether the return values should be ascii armored (true, the default) or binary (false)

streaming 'web' | 'ponyfill' | 'node' | false

(optional) whether to return data as a stream. Defaults to the type of stream message was created from, if any.

detached Boolean

(optional) if the return value should contain a 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 date of the signature

fromUserIds Array.<Object>

(optional) array of user IDs to sign with, one per key in privateKeys, e.g. [{ name:'Steve Sender', email:'steve@openpgp.org' }]

config Object

(optional) custom configuration settings to overwrite those in openpgp.config

Source:
Returns:

(String if armor was true, the default; Uint8Array if armor was false)

Type
Promise.<(String|ReadableStream.<String>|NodeStream.<String>|Uint8Array|ReadableStream.<Uint8Array>|NodeStream.<Uint8Array>)>

(async) unarmor(text) → {Promise.<Object>}

DeArmor an OpenPGP armored message; verify the checksum and return the encoded bytes

Parameters:
Name Type Description
text 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(publicKeys, message, format, streaming, signature, date, config) → {Promise.<Object>}

Verifies signatures of cleartext signed message

Parameters:
Name Type Description
publicKeys Key | Array.<Key>

array of publicKeys or single key, to verify signatures

message CleartextMessage | Message

(cleartext) message object with signatures

format 'utf8' | 'binary'

(optional) whether to return data as a string(Stream) or Uint8Array(Stream). If 'utf8' (the default), also normalize newlines.

streaming 'web' | 'ponyfill' | 'node' | false

(optional) whether to return data as a stream. Defaults to the type of stream message was created from, if any.

signature Signature

(optional) detached signature for verification

date Date

(optional) use the given date for verification instead of the current time

config Object

(optional) custom configuration settings to overwrite those in openpgp.config

Source:
Returns:

Object containing verified message in the form:

{
  data: String|ReadableStream<String>|NodeStream, (if `message` was a CleartextMessage)
  data: Uint8Array|ReadableStream<Uint8Array>|NodeStream, (if `message` was a Message)
  signatures: [
    {
      keyid: module:type/keyid~Keyid,
      verified: Promise<Boolean>,
      valid: Boolean (if `streaming` was false)
    }, ...
  ]
}
Type
Promise.<Object>