How to use the jsthemis.KeyPair 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 / 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 / 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