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