Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var keytok, ivtok, key, key1, key2, iv, encpass;
- var host;
- function storePass(encpass) {
- $.ajax({
- type: 'POST',
- url : 'example.php',
- data: { host: host, save: encpass },
- success: function(data, statuscode) {
- console.log('Password saved: ' + statuscode);
- },
- error: function() {
- console.log('Unable to save password.');
- }
- });
- }
- function startCrypt() {
- var crypt;
- host = document.getElementById("hostfield").value;
- $.ajax({
- type: 'POST',
- url: 'encrypt.php',
- data: { host: host },
- success: function(data, statuscode) {
- var encpass = '';
- crypt = data;
- crypt = JSON.parse(crypt);
- console.log('crypt is: "' + crypt + '"');
- crypt.key = crypt.key; //.toString(CryptoJS.enc.Latin1);
- crypt.iv = crypt.iv; //.toString(CryptoJS.enc.Latin1);
- encpass = CryptoJS.AES.encrypt( getPass(), crypt.key, { iv: crypt.iv } );
- console.log("Key: '" + crypt.key + "'");
- console.log("IV: '" + crypt.iv + "'");
- console.log("Encrypted Password: '" + encpass + "'");
- storePass(encpass);
- },
- error: function() {
- console.log('No data returned.');
- crypt = null;
- }
- });
- }
- function decrypt() {
- if(typeof iv === 'undefined' || typeof key === 'undefined') {
- console.log("Error decrypting. IV or Key is undefined.");
- return;
- }
- $.ajax({
- type: 'POST',
- url: 'decrypt.php',
- success: function(data, statuscode) {
- encpass = (JSON.parse(data)).encpass;
- var decrypted = CryptoJS.AES.decrypt(
- encpass,
- key,
- { iv: iv }
- );
- decrypted = decrypted.toString(CryptoJS.enc.Utf8);
- console.log("Decrypted Password: '" + decrypted + "'");
- },
- error: function() {
- console.log("Error decrypting. Could not retrieve encrypted password.");
- }
- });
- }
- function tokenRequest(type) {
- if(type != "key" && type != "iv") {
- console.log('ffs');
- return;
- }
- $.ajax({
- type: 'POST',
- url: './api/token/',
- data: { tokType: type, host: host },
- success: function(data, statuscode) {
- if(type == "key") {
- keytok = data;
- console.log(keytok);
- }
- else {
- ivtok = data;
- console.log(ivtok);
- }
- },
- error: function() {
- console.log('Something terrible happened.');
- }
- });
- }
- function getPass() {
- return document.getElementById("passfield").value;
- }
- function keyRequest() {
- $.ajax({
- dataType: 'jsonp',
- jsonp: 'keyReq:' + keytok,
- jsonpCallback: host,
- url: 'http://localhost:2343',
- });
- }
- function ivRequest() {
- $.ajax({
- dataType: 'jsonp',
- jsonp: 'ivReq:' + ivtok,
- jsonpCallback: host,
- url: 'http://localhost:2344',
- });
- }
- function procKey(data) {
- if('error' in data) {
- console.log(data.error);
- }
- else if('keys' in data) {
- key1 = data.keys[0];
- key2 = data.keys[1];
- key = makeKeys();
- console.log(key);
- }
- else {
- console.log("Undefined Behaviour");
- }
- }
- function procIv(data) {
- if('error' in data) {
- console.log(data.error);
- }
- else if('iv' in data) {
- iv = data.iv;
- console.log(iv);
- }
- else {
- console.log("Undefined Behaviour");
- }
- }
- function makeKeys(type) {
- console.log('making the keys');
- var fullKey = '';
- $.ajax({
- type: 'POST',
- url: './api/key/',
- data: { key1: key1, key2: key2 },
- success: function(data, statuscode) {
- fullKey = data;
- console.log(data);
- },
- error: function() {
- console.log('Something terrible happened.');
- }
- });
- return fullKey;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement