How to use the jsthemis.SecureSession 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 / docs / examples / js / secure_session_client.js View on Github external
var net = require('net');
var themis = require('jsthemis');

session = new themis.SecureSession(new Buffer.from("client"), new Buffer.from("UkVDMgAAAC3DZR2qAEbvO092R/IKXBttnf9dVSU65R+Fb4eNoyxxlzn2n4GR","base64"), function(id){
    if(id.toString()=="server".toString()){
	return new Buffer.from("VUVDMgAAAC30/vs+AwciK6egi82A9TkTydVuOzMFsJ9AkA0gMGyNH0tSu5Bk", "base64");
    }
    else if(id.toString()=="client".toString())
	return new Buffer.from("VUVDMgAAAC15KNjgAr1DQEw+So1oztUarO4Jw/CGgyehBRCbOxbpHrPBKO7s", "base64");
});

retry_count=5;

var client = new net.Socket();
client.connect(1337, '127.0.0.1', function() {
    console.log('Connected');
    client.write(session.connectRequest());
});

client.on('data', function(data) {
github cossacklabs / themis / docs / examples / js / secure_session_server.js View on Github external
var server = net.createServer(function(socket) {

    session = new themis.SecureSession(new Buffer.from("server"), new Buffer.from("UkVDMgAAAC0U6AK7AAm6ha0cgHmovSTpZax01+icg9xwFlZAqqGWeGTqbHUt","base64"), function(id){
	if(id.toString()=="server".toString())
	    return new Buffer.from("VUVDMgAAAC30/vs+AwciK6egi82A9TkTydVuOzMFsJ9AkA0gMGyNH0tSu5Bk", "base64");
	else if(id.toString()=="client".toString()){
	    return new Buffer.from("VUVDMgAAAC15KNjgAr1DQEw+So1oztUarO4Jw/CGgyehBRCbOxbpHrPBKO7s","base64");
	}
    });
  
    socket.on('data', function (data) {
	if(!(session.isEstablished())){
	    d=session.unwrap(data);
	    socket.write(d);
	}else{
	    d=session.unwrap(data);
	    console.log(d.toString());
	    socket.write(session.wrap(d));
	}

jsthemis

Themis is a convenient cryptographic library for data protection.

Apache-2.0
Latest version published 6 months ago

Package Health Score

75 / 100
Full package analysis