Security
Datum provides users to store their data on the Datum Blockchain. The encryption/decryption runs in the background with random generated keys, but you can also access this methods directly.
##Encrypt with AES256-CGM
const Datum = require('datum-sdk');
//sample data
var dataExample = {
email: "[email protected]"
}
//encrypt your data AES256-GCM and a secret. Normally the secret is generated and encrypted with your private key
var encryptedData = Datum.encrypt(data,"random_secret_generated");
console.log(encryptedData);
##Encryption using Public key
const Datum = require('datum-sdk');
//private secert
var secret = "Test1jöjöadsfölkjklsdajfökjakösdfkjfölöfsöf23";
var datum = new Datum();
//create identy for third party and encrypt with public key from third party then decrypt with private key to get plaintext secret back
var identity = Datum.createIdentity();
datum.encryptPublic(secret, '0x' + identity.publicKey);
.then(result => {
var priv = privKey.slice(2);
return client.decryptPublic(result,priv);
})
.then(decrypted => {
console.log(decrypted);
})
.catch((error) => {
console.log(error);
});
##Decryption using Private key
const Datum = require('datum-sdk');
//sample data from encryptPrivate.js
var encryptedData = 'U2FsdGVkX18zYeIsw42HFLGjmghHvAJpzbGIEjIQUnNjTVTbBYUsJHpalerrv1Jc';
//private secert
var secret = "Test1jöjöadsfölkjklsdajfökjakösdfkjfölöfsöf23";
//sample data
var dataExample = {
email: "[email protected]"
}
let datum = new Datum();
//encrypt data local with private secret
datum.decryptPrivate(encryptedData, secret)
.then(decryptedData => {
console.log(decryptedData);
})
.catch((error) => {
console.log(error);
});
##Hash function
const Datum = require('datum-sdk');
//sample data
var dataExample = {
email: "[email protected]"
}
//ATTENTION: json data must be stringified
let datum = new Datum();
datum.hash(JSON.stringify(dataExample)).then(hash => {
console.log(hash);
})
.catch((error) => {
console.log(error);
});