Getting started with Grapheene

Just the basics to get you up and running encrypting and decrypting your data!

This guide will get you started encrypting and decrypting data using Grapheene's systems.

When data is encrypted using Grapheene the encrypted data can be stored anywhere. This stored encrypted data can later be recalled and provided to the decrypt() function. Grapheene automatically determines which keys to apply to decrypt the encrypted data.

Prerequisites

  1. An account with Grapheene, a free account will work. To get started reach out to us here

  2. Either NodeJS or Python.

Installation

🚧

Version Requirement

For the Grapheene SDK to guarantee support of the crypto engine the below versions are required.

Node JS - Node v15 or higher

Python - Python 3.10.6 or higher

At this time Grapheene supports local package installs.

In your project folder install the Grapheene SDK for your preferred language.

npm install <path to this SDK>
pip install [path-to-wheel].whl

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

npm list
npm list

You should see a return something similar to this:

C:\Users\UserPro\Skills\OperationSecret>npm list
[email protected] C:\Users\UserPro\Skills\OperationSecret
`-- @grapheene/[email protected]:[email protected] -> .\..\typescript
C:\Users\UserPro\Skills\OperationSecret>npm list
[email protected] C:\Users\UserPro\Skills\OperationSecret
`-- @grapheene/[email protected]:[email protected] -> .\..\python

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. This script will complete multiple steps to encrypt using Grapheene.

import path from 'path'
import { KeyClient } from '@grapheene/nodejs'

// Defines the local directory where the generated keys will be stored.
const KeyStoreDir = path.join(__dirname, 'keystore')

async function main(): Promise<void> {
  // Creates the Key Client. 
  // The Key Client is configured to store generated keys in a local `keystore` directory.
   let client = await KeyClient.create({
      store: {
         file: {
            rootDir: KeyStoreDir
         }
      }
   })
   
   // Creates a Key Ring.
   // The Key Ring is responsible for managing the Keys used to encrypt data.
   // This will return an Object with the following shape:
   /*
      {
         ring: IKeyRing,
         keys: {
            private: string   // You're going to want to store this somewhere
            public: string    // This is used to encrypt keys in the KeyRing,
                                                                 that you will never have to see!
         }
      }
   */
   let result = await client.ring.create('new')
   let ring = result.ring
   
   // Uses the Key Ring to encrypt the data.
   let encrypted = await ring.encrypt("Hello!")
   
   // Uses the Key Ring to decrypt the data.
   let decrypted = await ring.decrypt(encrypted)
   
   // Displays the encrypted and decrypted string.
   console.log(`Encrypted: ${encrypted}`)
   console.log(`Decrypted: ${decrypted}`)
}

main()
   .then(_ => {
      console.log(`Success!`)
      process.exit(0)
   })
   .catch(err => {
      console.error(`Failed. Reason:\n${err}`)
      process.exit(1)
   })
async def main():

   client = await KeyClient.create()
   ring = await client.ring.create('XXXXX', error_if_exists=False)

   encrypted = await ring.encrypt("Some Text")
   
   decrypted = await ring.decrypt(encrypted)

Wasn't that easy?!