How to use jsthemis - 10 common examples

To help you get started, we’ve selected a few jsthemis examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cossacklabs / themis / tools / js / jsthemis / scell_seal_string_echo.js View on Github external
if (process.argv.length < 5 || process.argv.length > 6) {
    console.log('Usage:    ');
    process.exit(1);
}

var command = process.argv[2];
var key = new Buffer(process.argv[3]);
var message = process.argv[4];
var context = undefined;
if(process.argv.length === 6){
    var context = new Buffer(process.argv[5]);
}

if (command === "enc"){
    var message_buf = new Buffer(message);
    var encrypter = new jsthemis.SecureCellSeal(key);
    if (context){
        var result = encrypter.encrypt(message_buf, context);
    } else {
        var result = encrypter.encrypt(message_buf);
    }
    console.log(result.toString('base64'));
    process.exit(0)
} else if (command === 'dec'){
    var decrypter = new jsthemis.SecureCellSeal(key);
    var decoded_message = new Buffer(message, 'base64');
    if(context){
        var result = decrypter.decrypt(decoded_message, context);
    } else {
        var result = decrypter.decrypt(decoded_message);
    }
    console.log(result.toString('ascii'));
github cossacklabs / themis / tools / js / jsthemis / scell_seal_string_echo.js View on Github external
if(process.argv.length === 6){
    var context = new Buffer(process.argv[5]);
}

if (command === "enc"){
    var message_buf = new Buffer(message);
    var encrypter = new jsthemis.SecureCellSeal(key);
    if (context){
        var result = encrypter.encrypt(message_buf, context);
    } else {
        var result = encrypter.encrypt(message_buf);
    }
    console.log(result.toString('base64'));
    process.exit(0)
} else if (command === 'dec'){
    var decrypter = new jsthemis.SecureCellSeal(key);
    var decoded_message = new Buffer(message, 'base64');
    if(context){
        var result = decrypter.decrypt(decoded_message, context);
    } else {
        var result = decrypter.decrypt(decoded_message);
    }
    console.log(result.toString('ascii'));
    process.exit(0)
} else {
    console.log('Wrong command, use "enc" or "dec"');
    process.exit(1)
}
github cossacklabs / themis / tools / js / jsthemis / smessage_encryption.js View on Github external
const fs = require('fs');
const jsthemis = require('jsthemis');

if (process.argv.length !== 6) {
    console.log('Usage:    ');
    process.exit(1);
}

var command = process.argv[2];
var private_key = fs.readFileSync(process.argv[3])
var public_key = fs.readFileSync(process.argv[4])
var message = process.argv[5];

var smessage = jsthemis.SecureMessage(private_key, public_key);

if (command === "enc"){
    var message_buf = new Buffer(message);
    var result = smessage.encrypt(message_buf);
    console.log(result.toString('base64'));
    process.exit(0)
} else if (command === 'dec'){
    var decoded_message = new Buffer(message, 'base64');
    var result = smessage.decrypt(decoded_message);
    console.log(result.toString('ascii'));
    process.exit(0)
} else if (command === 'sign') {
    var message_buf = new Buffer(message);
    var result = smessage.sign(message_buf);
    console.log(result.toString('base64'));
    process.exit(0)
github cossacklabs / themis / tools / js / jsthemis / keygen.js View on Github external
const fs = require('fs');

if (process.argv.length !== 2 && process.argv.length !== 4) {
    console.log('Usage: node keygen.js  ');
    process.exit(1);
}

if (process.argv.length === 2) {
    var private_key_path = 'key';
    var public_key_path = 'key.pub';
} else if (process.argv.length === 4){
    var private_key_path = process.argv[2];
    var public_key_path = process.argv[3];
}

keypair = new jsthemis.KeyPair();

fs.writeFileSync(private_key_path, keypair.private(), {'mode': 0o400});
fs.writeFileSync(public_key_path, keypair.public());
github cossacklabs / themis / tools / js / jsthemis / scell_context_string_echo.js View on Github external
var jsthemis = require('jsthemis');

if (process.argv.length !== 6) {
    console.log('Usage:    ');
    process.exit(1);
}

var command = process.argv[2];
var key = new Buffer(process.argv[3]);
var message = process.argv[4];
var context = new Buffer(process.argv[5]);

if (command === "enc"){
    var message_buf = new Buffer(message);
    var encrypted = new jsthemis.SecureCellContextImprint(key);
    var result = encrypted.encrypt(message_buf, context);
    console.log(result.toString('base64'));
    process.exit(0)
} else if (command === 'dec'){
    var decrypter = new jsthemis.SecureCellContextImprint(key);
    var decoded_message = new Buffer(message, 'base64');
    var result = decrypter.decrypt(decoded_message, context);
    console.log(result.toString('ascii'));
    process.exit(0)
} else {
    console.log('Wrong command, use "enc" or "dec"');
    process.exit(1)
}
github cossacklabs / themis / tools / js / jsthemis / scell_context_string_echo.js View on Github external
process.exit(1);
}

var command = process.argv[2];
var key = new Buffer(process.argv[3]);
var message = process.argv[4];
var context = new Buffer(process.argv[5]);

if (command === "enc"){
    var message_buf = new Buffer(message);
    var encrypted = new jsthemis.SecureCellContextImprint(key);
    var result = encrypted.encrypt(message_buf, context);
    console.log(result.toString('base64'));
    process.exit(0)
} else if (command === 'dec'){
    var decrypter = new jsthemis.SecureCellContextImprint(key);
    var decoded_message = new Buffer(message, 'base64');
    var result = decrypter.decrypt(decoded_message, context);
    console.log(result.toString('ascii'));
    process.exit(0)
} else {
    console.log('Wrong command, use "enc" or "dec"');
    process.exit(1)
}
github cossacklabs / themis / tools / js / jsthemis / scell_token_string_echo.js View on Github external
if (process.argv.length < 5 || process.argv.length > 6) {
    console.log('Usage:    ');
    process.exit(1);
}

var command = process.argv[2];
var key = new Buffer(process.argv[3]);
var message = process.argv[4];
var context = undefined;
if(process.argv.length === 6){
    var context = new Buffer(process.argv[5]);
}

if (command === "enc"){
    var message_buf = new Buffer(message);
    var encrypter = new jsthemis.SecureCellTokenProtect(key);
    if (context){
        var result = encrypter.encrypt(message_buf, context);
    } else {
        var result = encrypter.encrypt(message_buf);
    }
    console.log([result.data.toString('base64'), result.token.toString('base64')].join(','));
    process.exit(0)
} else if (command === 'dec'){
    var splitted_message = message.split(',');
    var decrypter = new jsthemis.SecureCellTokenProtect(key);
    var decoded_message = new Buffer(splitted_message[0], 'base64');
    var decoded_token = new Buffer(splitted_message[1], 'base64');
    if(context){
        var result = decrypter.decrypt(decoded_message, decoded_token, context);
    } else {
        var result = decrypter.decrypt(decoded_message, decoded_token);
github cossacklabs / themis / tools / js / jsthemis / scell_token_string_echo.js View on Github external
var context = new Buffer(process.argv[5]);
}

if (command === "enc"){
    var message_buf = new Buffer(message);
    var encrypter = new jsthemis.SecureCellTokenProtect(key);
    if (context){
        var result = encrypter.encrypt(message_buf, context);
    } else {
        var result = encrypter.encrypt(message_buf);
    }
    console.log([result.data.toString('base64'), result.token.toString('base64')].join(','));
    process.exit(0)
} else if (command === 'dec'){
    var splitted_message = message.split(',');
    var decrypter = new jsthemis.SecureCellTokenProtect(key);
    var decoded_message = new Buffer(splitted_message[0], 'base64');
    var decoded_token = new Buffer(splitted_message[1], 'base64');
    if(context){
        var result = decrypter.decrypt(decoded_message, decoded_token, context);
    } else {
        var result = decrypter.decrypt(decoded_message, decoded_token);
    }
    console.log(result.toString('ascii'));
    process.exit(0)
} else {
    console.log('Wrong command, use "enc" or "dec"');
    process.exit(1)
}
github cossacklabs / themis / docs / examples / js / secure_cell.js View on Github external
var addon = require('jsthemis');


if(process.argv.length==5){
    command=process.argv[2];
    password=new Buffer.from(process.argv[3]);

    seal = new addon.SecureCellSeal(password);
    if(command=="enc"){
	console.log(seal.encrypt(new Buffer.from(process.argv[4])).toString("base64"));
    }else if(command=="dec"){
	console.log(seal.decrypt(new Buffer.from(process.argv[4], "base64")).toString());
    }else{
	console.log("usage node secure_cell.js   ");
    }
}else{
    console.log("usage node secure_cell.js   ");
}
github cossacklabs / themis / docs / examples / js / secure_message.js View on Github external
var addon = require('jsthemis');

if(process.argv.length==6){
    command=process.argv[2];
    private_key=process.argv[3];
    peer_public_key=process.argv[4];

    sm = new addon.SecureMessage(new Buffer.from(private_key, "base64"), new Buffer.from(peer_public_key, "base64"));
    if(command=="enc"){
        console.log(sm.encrypt(new Buffer.from(process.argv[5])).toString("base64"));
    }else if(command=="dec"){
	console.log(sm.decrypt(new Buffer.from(process.argv[5], "base64")).toString());
    }else{
        console.log("usage node secure_message.js    ");
    }
}else{
    console.log("usage node secure_message.js    ");
}

jsthemis

Themis is a convenient cryptographic library for data protection.

Apache-2.0
Latest version published 11 months ago

Package Health Score

74 / 100
Full package analysis