npm install cryptari
npm install cryptari --save
const Cryptari = require('cryptari');
const cryptari = new Cryptari({local:{masterKey:'A16ByteHexString'}});
`
$3
By either setting the CRYPTARI_LOCAL_MASTERKEY environment varaiable or passing the a 16 Byte Hex String key, a cryptari instance will use this key to encrypt and decrypt values.
`
const Cryptari = require('cryptari');
const cryptari = new Cryptari({local:{masterKey:'A16ByteHexString'}});
`
DO NOT ADD ANY OF THE IDS/SECRETS TO YOUR SOURCE CODE!
$3
Cryptari will auto-decect the following environments variables for AWS KMS
- CRYPTARI_AWS_ACCESS_KEY_ID The IAM User Id with acccess to the below key
- CRYPTARI_AWS_SECRET_ACCESS_KEY The matching secret of the IAM User
- CRYPTARI_AWS_CMK_ID The Id of the AWS master key
- CRYPTARI_AWS_REGION The region where the above master key is stored
Alternatively you can pass an options object as follows:
`
const Cryptari = require('cryptari');
const cryptari = new Cryptari({
aws:{
accessKeyId:'...',
secretAccessKey:'...',
cmkKeyId:'...',
region:'...',
}
});
`
Usage
$3
`
cryptari.encryptValue('Encrypt Me').then((encrypted)=>{
console.log(encrypted);
/// --> _cryptari.7f94f53730b61fd97823d8a8c804d25fc8847505daa8e925b34891bf908d6dad.dc2ec5bcd41a410adbe0.string.4213342259
cryptari.decryptValue(encrypted).then((decrypted){
console.log(decrypted);
// --> 'Encrypt Me'
});
});
`
$3
`
const testObject = {
foo:'Original',
bar:'Secret'
}
cryptari.encryptObject(testObject,['bar']).then(()=>{
console.log(JSON.stringify(testObject,2,2));
// property bar will be encrypted, property foo will be untouched
// -->
// {
// "foo": "Original",
// "bar": "_cryptari.7c6400980252c620a45e110b7d11213ab7fb74143603cac7adf834b161521531.a166af24c9c8.string.3137411440"
// }
cryptari.decryptObject(testObject,['bar']).then(()=>{
console.log(JSON.stringify(testObject,2,2));
// property bar will be decrypted, property foo will be untouched
// -->
// {
// "foo": "Original",
// "bar": "Secret"
// }
});
});
`
$3
`
const Promise = require('bluebird');
function testGenerator () {
return Promise.coroutine(function*() {
let encrypted = yield cryptari.encryptValue('test');
console.log(encrypted);
})();
}
`
$3
`
const Promise = require('bluebird');
function testGenerator () {
return Promise.coroutine(function*() {
let encrypted = yield cryptari.encryptValue('test');
console.log(encrypted);
})();
}
`
$3
By default cryptari-node will always return the value given to the encrypt/decrypt method if encryption/decryption fails
Alternatively you can also configure to cryptari to throw errors in the case of a failure.
Set the following enviroment variables for this:
CRYPTARI_ENCRYPTION_ONERROR=throw
CRYPTARI_DECRYPTION_ONERROR=throw`