Keystore.encrypt
Encrypts a private key as a JSON keystore using a derived key.
Supports the following key derivation functions (KDFs): - Keystore.pbkdf2
- Keystore.scrypt
Imports
Named
import { Keystore } from 'ox'
Examples
import { Keystore, Secp256k1 } from 'ox'
// Generate a random private key.
const privateKey = Secp256k1.randomPrivateKey()
// Derive key from password.
const [key, opts] = Keystore.pbkdf2({ password: 'testpassword' })
// Encrypt the private key.
const encrypted = Keystore.encrypt(privateKey, key, opts)
{ "crypto": { "cipher": "aes-128-ctr", "ciphertext": "...", "cipherparams": { "iv": "...", }, "kdf": "pbkdf2", "kdfparams": { "salt": "...", "dklen": 32, "prf": "hmac-sha256", "c": 262144, }, "mac": "...", }, "id": "...", "version": 3, }
Definition
function encrypt(
privateKey: Bytes.Bytes | Hex.Hex,
key: Key,
options: encrypt.Options,
): Keystore
Source: src/core/Keystore.ts
Parameters
privateKey
- Type:
Bytes.Bytes | Hex.Hex
Private key to encrypt.
key
- Type:
Key
Key to use for encryption.
options
- Type:
encrypt.Options
Encryption options.
options.c
- Type:
number
options.dklen
- Type:
number
options.id
- Type:
string
- Optional
UUID.
options.n
- Type:
number
options.p
- Type:
number
options.prf
- Type:
"hmac-sha256"
options.r
- Type:
number
options.salt
- Type:
string
Return Type
Encrypted keystore.