@sexycoders/libauth.js
Version:
A full service for asymetric passwordless authentication.
63 lines (54 loc) • 2.04 kB
JavaScript
function POST(system,post_data)
{
var seed=Math.floor(Math.random()*1000000000)+1;
//var signature=Sign(seed,user.rsa);
var signature=Sign(seed,system.pRSA);
var json_send=new Object();
json_send.command="message";
json_send.user=new Object();
json_send.user.id=system.user;
json_send.user.seed=seed;
json_send.user.sign=btoa(signature);
var t=new Object();
t.md = forge.md.md5.create();
t.md.update(system.hash);
var IV=t.md.digest().bytes();
delete t.md;
t.md = forge.md.sha256.create();
t.md.update(system.hash);
var cipher = forge.cipher.createCipher('AES-CBC',t.md.digest().bytes());
cipher.start({iv:IV});
cipher.update(forge.util.createBuffer(JSON.stringify(post_data)));
cipher.finish();
delete t.md;
json_send.data=btoa(cipher.output.bytes());
console.log("Json Is: "+JSON.stringify(json_send));
var to_return;
var send=btoa(JSON.stringify(json_send));
$.ajax({
type: 'POST',
headers: {"Access-Control-Allow-Origin":"localhost:56083"},
url: window.system.auth_server,
data: send,
success:
function(response)
{
var data=JSON.parse(atob(response));
var T=new Object();
T.md = forge.md.md5.create();
T.md.update(system.hash);
var IV=T.md.digest().bytes();
delete T.md;
T.md = forge.md.sha256.create();
T.md.update(system.hash);
var cipher = forge.cipher.createDecipher('AES-CBC',T.md.digest().bytes());
cipher.start({iv:IV});
cipher.update(forge.util.createBuffer(atob(data.data)));
cipher.finish();
delete T.md;
to_return=JSON.parse(cipher.output.bytes());
},
async:false
});
return to_return;
}