### libp2p-crypto

`0.19.2`
Need help reading this?

### import

src/keys/index.js
import(encryptedKey: string, password: string)
Parameters
encryptedKey `(string)`
password `(string)`

### import

src/keys/importer.js

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

src/ciphers/aes-gcm.js
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`:

### encrypt

src/ciphers/aes-gcm.js

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>`:

### decrypt

src/ciphers/aes-gcm.js

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

### id

src/keys/rsa-class.js

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.

id(): Promise<String>
Returns
`Promise<String>`:

### export

src/keys/rsa-class.js

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

src/keys/rsa.js
keypair

Type: PrivateKey

### export

src/keys/exporter.js

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

### id

src/keys/ed25519-class.js

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.

id(): Promise<String>
Returns
`Promise<String>`:

### export

src/keys/ed25519-class.js

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

### id

src/keys/secp256k1-class.js

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.

id(): Promise<string>
Returns
`Promise<string>`:

### export

src/keys/secp256k1-class.js

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

### pbkdf2

src/pbkdf2.js

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