How to use the jsthemis.SecureMessage function in jsthemis

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 / 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 / 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    ");
}
github cossacklabs / acra / wrappers / nodejs / acrawriter.js View on Github external
create_acrastruct: function(data, acra_public_key, context){
	var data_buffer = Buffer.isBuffer(data)?data:(new Buffer(data));
	var context_buffer = Buffer.isBuffer(context)?context:(new Buffer(context));
	var random_keypair = new themis.KeyPair();
	var sm = new themis.SecureMessage(random_keypair.private(), acra_public_key);
	var random_key = crypto.randomBytes(32);
	var wrapped_random_key = sm.encrypt(random_key);
	var sc = new themis.SecureCellSeal(random_key);
	crypto.randomFillSync(random_key);
	var encrypted_data = context?sc.encrypt(data_buffer, context_buffer):sc.encrypt(data_buffer);
	var begin_tag = new Buffer([34,34,34,34,34,34,34,34]);
	var encrypted_data_length = new int64(encrypted_data.length).toBuffer();
	return Buffer.concat([begin_tag, random_keypair.public(), wrapped_random_key, encrypted_data_length, encrypted_data]);
    }

jsthemis

Themis is a convenient cryptographic library for data protection.

Apache-2.0
Latest version published 1 year ago

Package Health Score

62 / 100
Full package analysis