Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
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 ");
}
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]);
}