encrypt

Encrypts data so it can only be read with the same key.

Parameter

Description

data

The data to encrypt, in any format that can be converted to JSON.

pair

A pair object with an epriv key, from pair(), work(), secret() or user.is.

callback

Optional function that receives the result. Leave it out to await it.

Returns an object with three properties, ct, iv and s, which can be stored with Holster and passed to decrypt(). Returns null if the pair has no epriv.

Examples

// With await.
const pair = await holster.SEA.pair()
const enc = await holster.SEA.encrypt("hello self", pair)
const dec = await holster.SEA.decrypt(enc, pair)
console.log(dec) // "hello self"

// With a callback.
holster.SEA.encrypt("hello self", pair, enc => console.log(enc.ct))

Encrypting data before writing it keeps it private, even though stored data can be read by anyone:

const enc = await holster.SEA.encrypt({phone: "0400 000 000"}, user.is)
await user.get("private").put(enc)

To encrypt data for someone else, create a shared key with secret().