# Class: SecretSubkeyPacket

## SecretSubkeyPacket(dateopt, configopt)

A Secret-Subkey packet (tag 7) is the subkey analog of the Secret Key packet and has exactly the same format.

## Constructor

#### new SecretSubkeyPacket(dateopt, configopt)

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`date` | Date | <optional> | Creation date
`config` | Object | <optional> | Full configuration, defaults to openpgp.config

Source:
  - packet/secret_subkey.js, line 36

### Extends

- SecretKeyPacket

### Members

#### aead :enums.aead

AEAD algorithm to encrypt the key with (if AEAD protection is enabled)

##### Type:

- enums.aead

Overrides:
  - SecretKeyPacket#aead
Source:
  - packet/secret_key.js, line 70

#### algorithm :enums.publicKey

Public key algorithm.

##### Type:

- enums.publicKey

Overrides:
  - SecretKeyPacket#algorithm
Source:
  - packet/public_key.js, line 60

#### created :Date

Key creation date.

##### Type:

- Date

Overrides:
  - SecretKeyPacket#created
Source:
  - packet/public_key.js, line 55

#### expirationTimeV3 :Integer

Time until expiration in days (V3 only)

##### Type:

- Integer

Overrides:
  - SecretKeyPacket#expirationTimeV3
Source:
  - packet/public_key.js, line 70

#### fingerprint :Uint8Array

Fingerprint bytes

##### Type:

- Uint8Array

Overrides:
  - SecretKeyPacket#fingerprint
Source:
  - packet/public_key.js, line 75

#### isEncrypted

Indicates whether secret-key data is encrypted. `this.isEncrypted === false` means data is available in decrypted form.

Overrides:
  - SecretKeyPacket#isEncrypted
Source:
  - packet/secret_key.js, line 50

#### keyID :module:type/keyid~KeyID

KeyID

##### Type:

- module:type/keyid~KeyID

Overrides:
  - SecretKeyPacket#keyID
Source:
  - packet/public_key.js, line 80

#### keyMaterial

Secret-key data

Overrides:
  - SecretKeyPacket#keyMaterial
Source:
  - packet/secret_key.js, line 46

#### privateParams :Object

Decrypted private parameters, referenced by name

##### Type:

- Object

Overrides:
  - SecretKeyPacket#privateParams
Source:
  - packet/secret_key.js, line 75

#### publicParams :Object

Algorithm specific public params

##### Type:

- Object

Overrides:
  - SecretKeyPacket#publicParams
Source:
  - packet/public_key.js, line 65

#### readPublicKey

Alias of read()

Overrides:
  - SecretKeyPacket#readPublicKey
Source:
  - packet/public_key.js, line 274
See:
  - PublicKeyPacket#read

#### s2k :type/s2k

S2K object

##### Type:

- type/s2k

Overrides:
  - SecretKeyPacket#s2k
Source:
  - packet/secret_key.js, line 60

#### s2kUsage :enums.symmetric

S2K usage

##### Type:

- enums.symmetric

Overrides:
  - SecretKeyPacket#s2kUsage
Source:
  - packet/secret_key.js, line 55

#### symmetric :enums.symmetric

Symmetric algorithm to encrypt the key with

##### Type:

- enums.symmetric

Overrides:
  - SecretKeyPacket#symmetric
Source:
  - packet/secret_key.js, line 65

#### version :Integer

Packet version

##### Type:

- Integer

Overrides:
  - SecretKeyPacket#version
Source:
  - packet/public_key.js, line 50

#### writePublicKey

Alias of write()

Overrides:
  - SecretKeyPacket#writePublicKey
Source:
  - packet/public_key.js, line 280
See:
  - PublicKeyPacket#write

### Methods

#### clearPrivateParams()

Clear private key parameters

Overrides:
  - SecretKeyPacket#clearPrivateParams
Source:
  - packet/secret_key.js, line 406

#### (async) computeFingerprint()

Computes and set the fingerprint of the key

Overrides:
  - SecretKeyPacket#computeFingerprint
Source:
  - packet/public_key.js, line 216

#### (async) computeFingerprintAndKeyID()

Computes and set the key ID and fingerprint of the key

Overrides:
  - SecretKeyPacket#computeFingerprintAndKeyID
Source:
  - packet/public_key.js, line 200

#### (async) decrypt(passphrase)

Decrypts the private key params which are needed to use the key. Successful decryption does not imply key integrity, call validate() to confirm that. SecretKeyPacket.isDecrypted should be false, as otherwise calls to this function will throw an error.

##### Parameters:

Name | Type | Description
--- | --- | ---
`passphrase` | String | The passphrase for this private key as string

Overrides:
  - SecretKeyPacket#decrypt
Source:
  - packet/secret_key.js, line 318

##### Throws:

if the key is already decrypted, or if decryption was not successful

Type
  Error

#### (async) encrypt(passphrase, configopt)

Encrypt the payload. By default, we use aes256 and iterated, salted string to key specifier. If the key is in a decrypted state (isEncrypted === false) and the passphrase is empty or undefined, the key will be set as not encrypted. This can be used to remove passphrase protection after calling decrypt().

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`passphrase` | String |  |
`config` | Object | <optional> | Full configuration, defaults to openpgp.config

Overrides:
  - SecretKeyPacket#encrypt
Source:
  - packet/secret_key.js, line 272

##### Throws:

if encryption was not successful

Type
  Error

#### getAlgorithmInfo() → {Object}

Returns algorithm information

Overrides:
  - SecretKeyPacket#getAlgorithmInfo
Source:
  - packet/public_key.js, line 256

##### Returns:

An object of the form {algorithm: String, bits:int, curve:String}.

Type
  Object

#### getCreationTime() → {Date}

Returns the creation time of the key

Overrides:
  - SecretKeyPacket#getCreationTime
Source:
  - packet/public_key.js, line 184

##### Returns:

Type
  Date

#### getFingerprint() → {String}

Calculates and returns the fingerprint of the key, as a string

Overrides:
  - SecretKeyPacket#getFingerprint
Source:
  - packet/public_key.js, line 240

##### Returns:

A string containing the fingerprint in lowercase hex

Type
  String

#### getFingerprintBytes() → {Uint8Array}

Returns the fingerprint of the key, as an array of bytes

Overrides:
  - SecretKeyPacket#getFingerprintBytes
Source:
  - packet/public_key.js, line 232

##### Returns:

A Uint8Array containing the fingerprint

Type
  Uint8Array

#### getKeyID() → {module:type/keyid~KeyID}

Return the key ID of the key

Overrides:
  - SecretKeyPacket#getKeyID
Source:
  - packet/public_key.js, line 192

##### Returns:

The 8-byte key ID

Type
  module:type/keyid~KeyID

#### hasSameFingerprintAs() → {Boolean}

Calculates whether two keys have the same fingerprint without actually calculating the fingerprint

Overrides:
  - SecretKeyPacket#hasSameFingerprintAs
Source:
  - packet/public_key.js, line 248

##### Returns:

Whether the two keys have the same version and public key data.

Type
  Boolean

#### isDecrypted() → {Boolean|null}

Check whether secret-key data is available in decrypted form. Returns false for gnu-dummy keys and null for public keys.

Overrides:
  - SecretKeyPacket#isDecrypted
Source:
  - packet/secret_key.js, line 228

##### Returns:

Type
  Boolean | null

#### isDummy() → {Boolean}

Check whether this is a gnu-dummy key

Overrides:
  - SecretKeyPacket#isDummy
Source:
  - packet/secret_key.js, line 236

##### Returns:

Type
  Boolean

#### makeDummy(configopt)

Remove private key material, converting the key to a dummy one. The resulting key cannot be used for signing/decrypting but can still verify signatures.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`config` | Object | <optional> | Full configuration, defaults to openpgp.config

Overrides:
  - SecretKeyPacket#makeDummy
Source:
  - packet/secret_key.js, line 245

#### (async) read(bytes)

Internal parser for private keys as specified in RFC4880bis-04 section 5.5.3

##### Parameters:

Name | Type | Description
--- | --- | ---
`bytes` | Uint8Array | Input string to read the packet from

Overrides:
  - SecretKeyPacket#read
Source:
  - packet/secret_key.js, line 86

#### (async) validate()

Checks that the key parameters are consistent

Overrides:
  - SecretKeyPacket#validate
Source:
  - packet/secret_key.js, line 375

##### Throws:

if validation was not successful

Type
  Error

#### write() → {Uint8Array}

Creates an OpenPGP key packet for the given key.

Overrides:
  - SecretKeyPacket#write
Source:
  - packet/secret_key.js, line 170

##### Returns:

A string of bytes containing the secret key OpenPGP packet.

Type
  Uint8Array

#### writeForHash(version)

Write packet in order to be hashed; either for a signature or a fingerprint

##### Parameters:

Name | Type | Description
--- | --- | ---
`version` | Integer | target version of signature or key

Overrides:
  - SecretKeyPacket#writeForHash
Source:
  - packet/public_key.js, line 163