Skip to main content

Decrypting data

We provide two methods to decrypt the data: decrypt and decryptValues.

The following workflow is applied when decrypting data:

  1. The encrypted symmetric key of the user for the provided encrypted data is obtained from blindnet
  2. The encrypted symmetric key is decrypted using the user's secret key
  3. Data is decrypted with the symmetric key

Only registered users can decrypt the data.


If the encrypted data is encoded, use the following helper methods to decode it before decrypting it.

import { util } from '@blindnet/sdk-javascript';

// if you use base64 encoding
const encryptedData = util.fromBase64(encodedData);
// if you use hex encoding
const encryptedData = util.fromHex(encodedData);

To decrypt the data, use

const { data, metadata } = await blindnet.decrypt(encryptedData);

data is the original data provided in the encrypt method.
metadata is the object provided in the encrypt method.

Metadata, besides the object fields provided in the encrypt method, will contain additional information on data format so it can be treated accordingly.

Additional information in metadata is under the key dataType, which can have the following values:

  • { type: 'STRING' } meaning data is a string
  • { type: 'FILE', name: string } meaning data is a file
  • { type: 'BYTES' } meaning data is ArrayBuffer