Getting started with Grapheene

References

Prerequisites

  1. NodeJS v15 or higher is required for Grapheene SDK. Please refer to the NodeJS installation instructions for your system.
  2. An account with Grapheene, a free account will work. Create an account here: Grapheene Sign up

Installation

🚧

NodeJS Version Requirement

Node v15 or higher is required for the Grapheene SDK to guarantee support of the crypto engine.

In the folder of your Node project, install the Grapheene Node Module.

npm i @grapheene/grapheene

After installing, you can check the Grapheene SDK version with the command

npm list

that will display something similar to this

[email protected] /Users/John/Documents/myFirstWithGrapheene
└── @grapheene/[email protected]

Configuration and Credentials

In order to securely access the cloud service, the Grapheene SDK requires a three-part credential system to get started.

A pair of Client ID and API Key is a service level credential. We recommend you create a new pair for each of your services or applications. This helps you to securely divide and manage the security of applications, modules and prototypes.

The Service Token is an account level credential, if necessary the Service Token can be rotated if you believe it has been compromised. Remember to set the new value in your secret management system, configuration files or env variables.

NodeJS Parameters

CLIENT_ID

  • Client ID : A service level credential paired with an API Key.

API_KEY

  • API Key : A service level credential paired with an API Key.

SERVICE_TOKEN

  • Service Token : An account level credential.

All credentials are accessible from the Grapheene Dashboard. See the below screenshot for where to find each key.

10361036

Your First Grapheene Application

It is time to perform your first encryption with Grapheene! The code snippet below is all you need to get started.

It creates a Key Ring, adds a Member to it and then encrypts and decrypts the data. Take a look!

📘

Your Grapheene Credentials are Needed!

Replace the credential placeholders in the first line with your credentials values from the Grapheene Dashboard.

const Grapheene = require('@grapheene/grapheene')('CLIENT_ID', 'API_KEY', 'SERVICE_TOKEN');
Grapheene.setup().then(() => {
    Grapheene.kmf.ring.create('My New Key Ring')
        .then(async (ring) => {
            const member = await ring.addMember({
                name: `[email protected]`
            })
            const encrypted = await member.data().encrypt('Some data content', 'myContentName');
            console.log('Encrypted: ', encrypted);
            const decrypted = await member.data().decrypt(encrypted);
            console.log('Decrypted: ', decrypted);
        }).catch((e) => {
        console.log(e.message);
    });
})

What should we expect to see?

Encrypted:  {
  name: 'myContentName',
  path: 'in:memory',
  encrypted: 'oWCÝ\x01ç\x81½(Ãî0\x82oä5²\x8E;æ«Â\x06X¢>gß¿«\x1AÕ¼k\b¡X£X\x03È\x7FhÃ,Á#8oÍtP\x07e\x83,»\x05´f\x055w]',
  service: 'unsaved'
}
Decrypted:  {
  name: 'myContentName',
  path: 'in:memory',
  encrypted: 'oWCÝ\x01ç\x81½(Ãî0\x82oä5²\x8E;æ«Â\x06X¢>gß¿«\x1AÕ¼k\b¡X£X\x03È\x7FhÃ,Á#8oÍtP\x07e\x83,»\x05´f\x055w]',
  service: 'unsaved',
  decrypted: 'Some data content'
}

Wasn't that easy!!

Now you are ready to try out some of our encryption recipes!


Did this page help you?