encrypt
Encrypts data so it can only be read with the same key.
Parameter | Description |
|---|---|
| The data to encrypt, in any format that can be converted to JSON. |
| A pair object with an |
| Optional function that receives the result. Leave it out to |
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().