var cipherText = sjcl.encrypt("password", "data"); console.log(cipherText); var plainText = sjcl.decrypt("password", cipherText); console.log(plainText); var field = document.getElementById('crypt'); // field.innerText = plainText; var jsonString = "{\"iv\":\"2rtnuXaJXFuQGO9ncaVkmA==\",\"v\":1,\"iter\":10000,\"ks\":128,\"ts\":64,\"mode\":\"ccm\",\"adata\":\"\",\"cipher\":\"aes\",\"salt\":\"H1z7o3f6qlQ=\",\"ct\":\"lF9Uno7ihjVv01M8\"}"; var myJSON = JSON.parse(jsonString); console.log(myJSON); // let base64 = require('base-64'); let headers = new Headers(); console.log("Token = " + btoa("hmm" + ":" + "hmm")) // headers.append('Accept','application/json') // headers.append('Content-Type', 'application/json'); headers.append('Authorization', 'Basic ' + btoa("hmm" + ":" + "hmm")); // headers.append('Authorization', 'Basic aG1tOmhtbQ=='); // aG1tOmhtbQ== var messageCipher; fetch('http://localhost:8080/api/messages', { method: 'GET', headers: headers // credentials: 'include' }).then(response => response.json()) .then(json => { // console.log('parsed json', JSON.stringify(json)) // access json.body here // console.log('parsed json', json[0].messageCipher); messageCipher = JSON.stringify(json[0].messageCipher); console.log(messageCipher); console.log(sjcl.decrypt("password", messageCipher)); }); // console.log("New message = " + messageCipher); // [{"messageID":5,"fromUser":{"userID":3,"userName":"user2","joinDate":1569224699000},"toUser":{"userID":6,"userName":"novo","joinDate":1569224706000},"messageCipher":{"iv":"2rtnuXaJXFuQGO9ncaVkmA==","v":1,"mode":"ccm","adata":"","cipher":"aes","salt":"H1z7o3f6qlQ=","iter":10000,"ks":128,"ts":64,"ct":"lF9Uno7ihjVv01M8"},"messageTime":1569685335000}] var url = 'http://localhost:8080/api/users' xml = new XMLHttpRequest(); xml.onreadystatechange = function () { if (xml.readyState == XMLHttpRequest.DONE) { // alert(xhr.responseText); console.log(xml.responseText); // console.log(xml.getResponseHeader('X-CSRF-TOKEN')); } } xml.open('GET', url) xml.setRequestHeader('Authorization', 'Basic aG1tOmhtbQ=='); xml.setRequestHeader("X-CSRF-TOKEN", "fetch"); xml.send(null);