Skip to main content

Quick Start Guide

info

While reading this quickstart guide you can download and follow the source code for a simple React front-end app with integrated blindnet client SDK from here.

In this quickstart guide, you will learn how to encrypt and decrypt a file using the blindnet encryption client SDK.
We assume two users exist - a user we know, Alice, and an anonymous user Bob. For the sake of simplicity, we'll act as both Alice and Bob. We will register a known user Alice to the blindnet encryption service, encrypt a file to her as an anonymous user Bob, and then decrypt the file as Alice.

You will learn how to:

  • set-up the blindnet encryption engine
  • register Alice to the blindnet encryption service
  • encrypt a file as Bob
  • decrypt a file as Alice

Before you start

You first need to obtain authentication data (application id and key) from the blindnet dashboard.

Refer to Access Management - Application Set Up for instructions.

STEP 1: Set-up

To generate the authentication tokens, we will use a dedicated token generator. In your production environment, you will need both client and server SDKs and generate the tokens on the server side.

Installation

To install the blindnet encryption library and the token generator:

npm i -S @blindnet/sdk-javascript @blindnet/token-generator

Import

Import the library to your project with:

import { Blindnet } from '@blindnet/sdk-javascript';
import { createTempUserToken, createUserToken } from '@blindnet/token-generator';

Generate a user token for Alice

Tokens are used to authenticate the users of your application to the blindnet encryption service. They can be used multiple times and should be regenerated when they expire using the same method.

caution

We use the token generation library to generate the tokens. It should be only used for testing purposes and tokens should be generated on the server in the production environment, after your user is authenticated.

Use the application id and key you obtained in Before you start section.

const appId = 'your_application_id';
const appKey = 'your_application_key';
const aliceId = 'alice';
const groupId = 'test-group';
const token = await createUserToken(aliceId, groupId, appId, appKey);

Specify the testing endpoint and initialize the library for Alice

const endpoint = 'https://test.blindnet.io';
const blindnet = Blindnet.init(token, endpoint);

Connect Alice to the blindnet encryption service

The blindnet encryption service can encrypt files with a particular destination (list of users or a user group) in mind. So in order to start encrypting, you first need to have some users (Alice in this case) that you've connected to the blindnet encryption service.

To connect a user to the blindnet encryption service, a secret value has to be provided. That value must only be known by the user (e.g. user's password). In that case, it's important not to use the same value to log-into your system and connect to the blindnet encryption service for which we provide a method deriveSecrets.

const { appSecret, blindnetSecret } = await Blindnet.deriveSecrets(secret);
await blindnet.connect(blindnetSecret);
info

You can use appSecret as a password for the user to log into your system.

STEP 2: Encrypt a file

After Alice has connected to the blindnet encryption service, data can be encrypted for her. We will simulate an anonymous user Bob encrypting a file for Alice.

Initialize SDK for Bob

You need to initialize the library with the temporary token in order to encrypt the data. Pass the id of the group Alice belongs to in order to give permission to encrypt data for her.

const token = await createTempUserToken(groupId, appId, appKey);
const blindnet = Blindnet.init(token, endpoint);

Encrypt a file

Obtain a file from the <input type="file" id="file-pick> HTML element and pass it to the encrypt method. Add Alice as a recipient.

const file = document.getElementById('file-pick').files[0];
const { encryptedData } = await blindnet.capture(data).forUser(aliceId).encrypt();

encryptedData should be stored by you.

STEP 3: Decrypt a file

To decrypt a file, you only need encryptedData.

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

There is a convenient library to save files file-saver.

saveAs(data, metadata.name);