Module: key

Requires

Classes

Key
SubKey
User

Methods

(static) createSignaturePacket(dataToSign, signingKeyPacket, signatureProperties, date, userId) → {module:packet/signature}

Create signature packet

Parameters:
Name Type Description
dataToSign Object

Contains packets to be signed

signingKeyPacket module:packet.SecretKey | module:packet.SecretSubkey

secret key packet for signing

signatureProperties Object

(optional) properties to write on the signature packet before signing

date Date

(optional) override the creationtime of the signature

userId Object

(optional) user ID

Source:
Returns:

signature packet

Type
module:packet/signature

(async, static) generate(curve, date, subkeys) → {Promise.<module:key.Key>}

Generates a new OpenPGP key. Supports RSA and ECC keys. Primary and subkey will be of same type.

Parameters:
Name Type Attributes Default Description
options.keyType module:enums.publicKey <optional>
module:enums.publicKey.rsa_encrypt_sign

To indicate what type of key to make. RSA is 1. See https://tools.ietf.org/html/rfc4880#section-9.1

options.numBits Integer

number of bits for the key creation.

options.userIds String | Array.<String>

Assumes already in form of "User Name username@email.com" If array is used, the first userId is set as primary user Id

options.passphrase String

The passphrase used to encrypt the resulting private key

options.keyExpirationTime Number <optional>
0

The number of seconds after the key creation time that the key expires

curve String

(optional) elliptic curve for ECC keys

date Date

Override the creation date of the key and the key signatures

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

Source:
Returns:
Type
Promise.<module:key.Key>

(async, static) getPreferredAlgo(type, keys, date, userId) → {Promise.<module:enums.symmetric>}

Returns the preferred symmetric/aead algorithm for a set of keys

Parameters:
Name Type Description
type symmetric | aead

Type of preference to return

keys Array.<module:key.Key>

Set of keys

date Date

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

userId Object

(optional) user ID

Source:
Returns:

Preferred symmetric algorithm

Type
Promise.<module:enums.symmetric>

(async, static) getPreferredHashAlgo(key, keyPacket, date, userId) → {Promise.<String>}

Returns the preferred signature hash algorithm of a key

Parameters:
Name Type Description
key module:key.Key

(optional) the key to get preferences from

keyPacket module:packet.SecretKey | module:packet.SecretSubkey

key packet used for signing

date Date

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

userId Object

(optional) user ID

Source:
Returns:
Type
Promise.<String>

(async, static) isAeadSupported(keys, date) → {Promise.<Boolean>}

Returns whether aead is supported by all keys in the set

Parameters:
Name Type Description
keys Array.<module:key.Key>

Set of keys

date Date

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

Source:
Returns:
Type
Promise.<Boolean>

(async, static) read(data) → {Promise.<{keys: Array.<module:key.Key>, err: (Array.<Error>|null)}>}

Reads an unarmored OpenPGP key list and returns one or multiple key objects

Parameters:
Name Type Description
data Uint8Array

to be parsed

Source:
Returns:

result object with key and error arrays

Type
Promise.<{keys: Array.<module:key.Key>, err: (Array.<Error>|null)}>

(async, static) readArmored(armoredText) → {Promise.<{keys: Array.<module:key.Key>, err: (Array.<Error>|null)}>}

Reads an OpenPGP armored text and returns one or multiple key objects

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

text to be parsed

Source:
Returns:

result object with key and error arrays

Type
Promise.<{keys: Array.<module:key.Key>, err: (Array.<Error>|null)}>

(async, static) reformat(date, subkeys) → {Promise.<module:key.Key>}

Reformats and signs an OpenPGP key with a given User ID. Currently only supports RSA keys.

Parameters:
Name Type Attributes Default Description
options.privateKey module:key.Key

The private key to reformat

options.keyType module:enums.publicKey <optional>
module:enums.publicKey.rsa_encrypt_sign
options.userIds String | Array.<String>

Assumes already in form of "User Name username@email.com" If array is used, the first userId is set as primary user Id

options.passphrase String

The passphrase used to encrypt the resulting private key

options.keyExpirationTime Number <optional>
0

The number of seconds after the key creation time that the key expires

date Date

Override the creation date of the key and the key signatures

subkeys Array.<Object>

(optional) options for each subkey, default to main key options. e.g. [{sign: true, passphrase: '123'}]

Source:
Returns:
Type
Promise.<module:key.Key>

(inner) getLatestSignature(signatures, date) → {module:packet.Signature}

Returns the signature that has the latest creation date, while ignoring signatures created in the future.

Parameters:
Name Type Description
signatures Array.<module:packet.Signature>

List of signatures

date Date

Use the given date instead of the current time

Source:
Returns:

The latest signature

Type
module:packet.Signature

(async, inner) isDataRevoked(primaryKey, dataToVerify, revocations, signature, key,, date) → {Promise.<Boolean>}

Checks if a given certificate or binding signature is revoked

Parameters:
Name Type Description
primaryKey module:packet.SecretKey | module:packet.PublicKey

The primary key packet

dataToVerify Object

The data to check

revocations Array.<module:packet.Signature>

The revocation signatures to check

signature module:packet.Signature

The certificate or signature to check

key, module:packet.PublicSubkey | module:packet.SecretSubkey | module:packet.PublicKey | module:packet.SecretKey

optional The key packet to check the signature

date Date

Use the given date instead of the current time

Source:
Returns:

True if the signature revokes the data

Type
Promise.<Boolean>