@sexycoders/libauth.js
Version:
A full service for asymetric passwordless authentication.
40 lines (35 loc) • 1.42 kB
JavaScript
function ssh_create(e,async_flag)
{
var ssh=new Object();
ssh.alg="RSASSA-PKCS1-v1_5";
ssh.size="4096";
ssh.name="username";
var keys=generateKeyPair(ssh.alg, ssh.size, ssh.name);
//returns array promise first cell is private and second is public
keys.then(function(keys){
var privateKey=atob(keys[0]);
var publicKey=keys[1];
//localStorage.setItem("SSH_Public",publicKey);
window.__auth_system._rsa=publicKey;
window.__auth_system.pRSA=privateKey;
//hashing password with md5 for IV
var md = forge.md.md5.create();
md.update(e.password);
var cipher = forge.cipher.createCipher('AES-CBC',md.digest().toHex());
delete md;
var md = forge.md.sha256.create();
md.update(e.password);
cipher.start({iv: md.digest().toHex().substring(0,16)});
cipher.update(forge.util.createBuffer(privateKey));
cipher.finish();
var encrypted = cipher.output;
delete md;
window.__auth_system._enc_prsa=btoa(encrypted.data);
//console.log(window.__auth_system._enc_prsa);
if(async_flag)
{
var t=new Event("SSH_CREATE_SIG");
window.dispatchEvent(t);
}
});
};