decrypt

Decrypts data from encrypt().

Parameter

Description

enc

The object returned by encrypt(), with ct, iv and s properties.

pair

A pair object with the same epriv key the data was encrypted with.

callback

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

Returns the original data, in the same format it was passed to encrypt(). Returns null if the key is wrong or the data can't be decrypted.

Examples

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

// With a callback.
holster.SEA.decrypt(enc, pair, dec => console.log(dec.message))

Reading back data that was encrypted and stored:

const enc = await user.get("private")
const data = await holster.SEA.decrypt(enc, user.is)