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
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
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>
After installing, you can check the Grapheene SDK version with the following command:
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
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)
})
Wasn't that easy?!
Updated about 2 months ago