import(encryptedKey: string, password: string)
Parameters
encryptedKey (string)
password (string)

Attempts to decrypt a base64 encoded PrivateKey string with the given password. The privateKey must have been exported using the same password and underlying cipher (aes-gcm)

import(privateKey: string, password: string): Promise<Uint8Array>
Parameters
privateKey (string) A base64 encoded encrypted key
password (string)
Returns
Promise<Uint8Array>: The private key protobuf
create(options: object?): any
Parameters
options (object? = {})
Name Description
options.algorithmTagLength Number (default 16)
options.nonceLength Number (default 12)
options.keyLength Number (default 16)
options.digest string (default sha256)
options.saltLength Number (default 16)
options.iterations Number (default 32767)
Returns
any:

Uses the provided password to derive a pbkdf2 key. The key will then be used to encrypt the data.

encrypt(data: Uint8Array, password: (string | Uint8Array)): Promise<Uint8Array>
Parameters
data (Uint8Array) The data to decrypt
password ((string | Uint8Array)) A plain password
Returns
Promise<Uint8Array>:

Uses the provided password to derive a pbkdf2 key. The key will then be used to decrypt the data. The options used to create this decryption cipher must be the same as those used to create the encryption cipher.

decrypt(data: Uint8Array, password: (string | Uint8Array))
Parameters
data (Uint8Array) The data to decrypt
password ((string | Uint8Array)) A plain password

Gets the ID of the key.

The key id is the base58 encoding of the SHA-256 multihash of its public key. The public key is a protobuf encoding containing a type and the DER encoding of the PKCS SubjectPublicKeyInfo.

Returns
Promise<String>:

Exports the key into a password protected PEM format

export(password: string, format: string)
Parameters
password (string) The password to read the encrypted PEM
format (string = pkcs-8) The format in which to export as
keypair

Type: PrivateKey

Exports the given PrivateKey as a base64 encoded string. The PrivateKey is encrypted via a password derived PBKDF2 key leveraging the aes-gcm cipher algorithm.

export(privateKey: Uint8Array, password: string): Promise<string>
Parameters
privateKey (Uint8Array) The PrivateKey protobuf
password (string)
Returns
Promise<string>: A base64 encoded string

Gets the ID of the key.

The key id is the base58 encoding of the SHA-256 multihash of its public key. The public key is a protobuf encoding containing a type and the DER encoding of the PKCS SubjectPublicKeyInfo.

Returns
Promise<String>:

Exports the key into a password protected format

export(password: string, format: string): Promise<Uint8Array>
Parameters
password (string) The password to encrypt the key
format (string = libp2p-key) The format in which to export as
Returns
Promise<Uint8Array>: The encrypted private key

Gets the ID of the key.

The key id is the base58 encoding of the SHA-256 multihash of its public key. The public key is a protobuf encoding containing a type and the DER encoding of the PKCS SubjectPublicKeyInfo.

Returns
Promise<string>:

Exports the key into a password protected format

export(password: string, format: string): Promise<string>
Parameters
password (string) The password to encrypt the key
format (string = libp2p-key) The format in which to export as
Returns
Promise<string>: The encrypted private key

Computes the Password-Based Key Derivation Function 2.

pbkdf2(password: string, salt: string, iterations: number, keySize: number, hash: string): string
Parameters
password (string)
salt (string)
iterations (number)
keySize (number) (in bytes)
hash (string) The hash name ('sha1', 'sha2-512, ...)
Returns
string: A new password