# Class: Key

## key~ Key

Class that represents an OpenPGP key. Must contain a primary key. Can contain additional subkeys, signatures, user ids, user attributes.

#### new Key(packetlist)

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `packetlist` | module:packet/packetlist | The packets that form this key

  Source:
    - key.js, line 32

### Methods

#### armor() → {String}

  Returns ASCII armored text of key
  Source:
    - key.js, line 279

  ##### Returns:

  ASCII armor
  Type
    String

#### decrypt(passphrase) → {Boolean}

  Decrypts all secret key and subkey packets

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `passphrase` | String |

  Source:
    - key.js, line 363

  ##### Returns:

  true if all key and subkey packets decrypted successfully
  Type
    Boolean

#### decryptKeyPacket(keyIds, passphrase) → {Boolean}

  Decrypts specific key packets by key ID

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `keyIds` | Array.<module:type/keyid> |
  `passphrase` | String |

  Source:
    - key.js, line 382

  ##### Returns:

  true if all key packets decrypted successfully
  Type
    Boolean

#### getAllKeyPackets() → {Array.<(module:packet/public_subkey|module:packet/secret_subkey|module:packet/secret_key|module:packet/public_key)>}

  Returns all the private and public key and subkey packets
  Source:
    - key.js, line 162

  ##### Returns:

  Type
    Array.<(module:packet/public_subkey|module:packet/secret_subkey|module:packet/secret_key|module:packet/public_key)>

#### getEncryptionKeyPacket() → {module:packet/public_subkey|module:packet/secret_subkey|module:packet/secret_key|module:packet/public_key|null}

  Returns the first valid encryption key packet for this key
  Source:
    - key.js, line 339

  ##### Returns:

  key packet or null if no encryption key has been found
  Type
    module:packet/public_subkey | module:packet/secret_subkey | module:packet/secret_key | module:packet/public_key | null

#### getKeyIds() → {Array.<module:type/keyid>}

  Returns key IDs of all key packets
  Source:
    - key.js, line 170

  ##### Returns:

  Type
    Array.<module:type/keyid>

#### getKeyPacket() → {module:packet/secret_key|module:packet/public_key|null}

  Returns the primary key packet (secret or public)
  Source:
    - key.js, line 140

  ##### Returns:

  Type
    module:packet/secret_key | module:packet/public_key | null

#### getPreferredHashAlgorithm() → {String}

  Returns preferred signature hash algorithm of this key
  Source:
    - key.js, line 311

  ##### Returns:

  Type
    String

#### getPrimaryUser() → {Object}

  Returns primary user and most significant (latest valid) self signature - if multiple users are marked as primary users returns the one with the latest self signature - if no primary user is found returns the user with the latest self signature
  Source:
    - key.js, line 447

  ##### Returns:

  The primary user and the self signature
  Type
    Object

#### getPrivateKeyPacket(keyIds) → {module:packet/secret_subkey|module:packet/secret_key|null}

  Returns first private key packet for given array of key IDs

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `keyIds` | Array.<module:type/keyid> |

  Source:
    - key.js, line 209

  ##### Returns:

  Type
    module:packet/secret_subkey | module:packet/secret_key | null

#### getPublicKeyPacket(keyIds) → {module:packet/public_subkey|module:packet/public_key|null}

  Returns first public key packet for given array of key IDs

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `keyIds` | Array.<module:type/keyid> |

  Source:
    - key.js, line 196

  ##### Returns:

  Type
    module:packet/public_subkey | module:packet/public_key | null

#### getSigningKeyPacket() → {module:packet/secret_subkey|module:packet/secret_key|null}

  Returns first key packet that is available for signing
  Source:
    - key.js, line 288

  ##### Returns:

  key packet or null if no signing key has been found
  Type
    module:packet/secret_subkey | module:packet/secret_key | null

#### getSubkeyPackets() → {Array.<(module:packet/public_subkey|module:packet/secret_subkey)>}

  Returns all the private and public subkey packets
  Source:
    - key.js, line 148

  ##### Returns:

  Type
    Array.<(module:packet/public_subkey|module:packet/secret_subkey)>

#### getUserIds() → {Array.<string>}

  Returns userids
  Source:
    - key.js, line 221

  ##### Returns:

  array of userids
  Type
    Array.<string>

#### isPrivate() → {Boolean}

  Returns true if this is a private key
  Source:
    - key.js, line 243

  ##### Returns:

  Type
    Boolean

#### isPublic() → {Boolean}

  Returns true if this is a public key
  Source:
    - key.js, line 235

  ##### Returns:

  Type
    Boolean

#### packetlist2structure(packetlist)

  Transforms packetlist to structured key data

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `packetlist` | module:packet/packetlist | The packets that form a key

  Source:
    - key.js, line 52

#### toPacketlist() → {module:packet/packetlist}

  Transforms structured key data to packetlist
  Source:
    - key.js, line 120

  ##### Returns:

  The packets that form a key
  Type
    module:packet/packetlist

#### toPublic() → {module:key~Key}

  Returns key as public key (shallow copy)
  Source:
    - key.js, line 251

  ##### Returns:

  new public Key
  Type
    module:key~Key

#### verifyPrimaryKey() → {module:enums.keyStatus}

  Verify primary key. Checks for revocation signatures, expiration time and valid self signature
  Source:
    - key.js, line 405

  ##### Returns:

  The status of the primary key
  Type
    module:enums.keyStatus