当我加密数据并将其发送到服务器时,什么也没出现

时间:2019-06-01 20:14:47

标签: javascript html encryption cryptojs

我什至不知道我说的是一个非常奇怪的问题,浏览器内部的数据加密良好,而且一切正常,当我将其发送到服务器时,服务器会看到加密的文本,但是当我看到未加密的文本时,我什么也看不到(不是空了,什么都没有了),并尽了最大的努力(例如用加密的文本覆盖文本并发送并在新的位置添加加密的文本,然后将其发送到服务器,甚至制作了标签),但是没有任何帮助?

enter image description here

添加数据页面的代码

let name = document.getElementById("name").value;
let medicName = document.getElementById("medic-name").value;
let medicTime = document.getElementById("medic-time").value;
let notes = document.getElementById("notes").value;

let myPassword = "lol";

let encryptedName = CryptoJS.AES.encrypt(name, myPassword);
let encryptedMedicName = CryptoJS.AES.encrypt(medicName, myPassword);
let encryptedMedicTime = CryptoJS.AES.encrypt(medicTime, myPassword);
let encryptedNotes = CryptoJS.AES.encrypt(notes, myPassword);

let config = {
  apiKey: "AIzaSyBZHH97LQ42n7j0fBjKR7LCLXkeDq-L7iw",
  authDomain: "pro-core-169202.firebaseapp.com",
  databaseURL: "https://pro-core-169202.firebaseio.com",
  projectId: "pro-core-169202",
  storageBucket: "pro-core-169202.appspot.com",
  messagingSenderId: "58388231689"
};
firebase.initializeApp(config);

let dataRef = firebase.database().ref("data");

function encrypt() {
    document.getElementById("encryptednameHTML").innerHTML = encryptedName;
    document.getElementById("encryptedmedicnameHTML").innerHTML = encryptedMedicName;
    document.getElementById("encryptedmedictimeHTML").innerHTML = encryptedMedicTime;
    document.getElementById("encryptednotesHTML").innerHTML = encryptedNotes;
}

// document.getElementById("dataform").addEventListener("submit", submitform);
// function submitform(e) {
//  e.preventDefault();


// }

document.getElementById("encrypted").addEventListener("submit", submitform); 
function submitform(e) {
    e.preventDefault();
     saveData(encryptednameHTML.innerHTML, encryptedmedicnameHTML.innerHTML, encryptedmedictimeHTML.innerHTML, encryptednotesHTML.innerHTML);

   }

function saveData(encryptednameHTML, encryptedmedicnameHTML, encryptedMedicTimeHTML, encryptedNotesHTML) {
  let newDataRef = dataRef.push();
  newDataRef.set({
    name: encryptednameHTML,
    medicName: encryptedmedicnameHTML,
    medicTime: encryptedMedicTimeHTML,
    notes: encryptedNotesHTML
  });
alert("Data Added!");
}

显示数据页面的代码

//DataBase Code
config = {
    apiKey: "AIzaSyBZHH97LQ42n7j0fBjKR7LCLXkeDq-L7iw",
    authDomain: "pro-core-169202.firebaseapp.com",
    databaseURL: "https://pro-core-169202.firebaseio.com",
    projectId: "pro-core-169202",
    storageBucket: "pro-core-169202.appspot.com",
    messagingSenderId: "58388231689"
  };
  firebase.initializeApp(config);
// End Of DataBase Code

// Login Code
  firebase.auth().onAuthStateChanged(function(user) {
    if (user) {
  document.getElementById("loginsys").style.display = "none";
  document.getElementById("dataShowEncrypted").style.display = "none";
  document.getElementById("dataShowDecrypted").style.display = "block";
  document.getElementById("logout").style.display = "block";


    } else {
      document.getElementById("loginsys").style.display = "block";
      document.getElementById("dataShowEncrypted").style.display = "block";
      document.getElementById("dataShowDecrypted").style.display = "none";
      document.getElementById("logout").style.display = "none";

        }
  });

  function login(){
  let userEmail = document.getElementById("email").value;
  let userPass = document.getElementById("password").value;

  firebase.auth().signInWithEmailAndPassword(userEmail, userPass).catch(function(error) {
    // Handle Errors here.
    var errorCode = error.code;
    var errorMessage = error.message;
    // ...
    alert("Error: " + errorMessage + ", " + "Error Code: " + errorCode );
  });

  }

  function logout() {
    firebase.auth().signOut();

  }
// End Of Login Code

// Show Data Code

  let dataRef = firebase.database().ref("data");

  dataRef.on("child_added", snap => {

    let name = snap.child("name").val();
    let medicName = snap.child("medicName").val();
    let medicTime = snap.child("medicTime").val();
    let notes = snap.child("notes").val();

    let myPassword = "lol";

    let decryptedName = CryptoJS.AES.decrypt(name, myPassword).toString(CryptoJS.enc.Utf8);
    let decryptedMedicName = CryptoJS.AES.decrypt(medicName, myPassword).toString(CryptoJS.enc.Utf8);
    let decryptedMedicTime = CryptoJS.AES.decrypt(medicTime, myPassword).toString(CryptoJS.enc.Utf8);
    let decryptedNotes = CryptoJS.AES.decrypt(notes, myPassword).toString(CryptoJS.enc.Utf8);

    $("#dataShowEncrypted").append("<tr><td>" + "Name: " + name + "</td><td>" + "&nbsp;&nbsp;--&nbsp;&nbsp;" + " Medic Name: " + medicName + "</td><td>" + "&nbsp;&nbsp;--&nbsp;&nbsp;" + " Medic Time: " + medicTime + "</td><td>" + "&nbsp;&nbsp;--&nbsp;&nbsp;" + " Notes: " + notes + "<br>");
    $("#dataShowDecrypted").append("<tr><td>" + "Name: " + decryptedName + "</td><td>" + "&nbsp;&nbsp;--&nbsp;&nbsp;" + " Medic Name: " + decryptedMedicName + "</td><td>" + "&nbsp;&nbsp;--&nbsp;&nbsp;" + " Medic Time: " + decryptedMedicTime + "</td><td>" + "&nbsp;&nbsp;--&nbsp;&nbsp;" + " Notes: " + decryptedNotes + "<br>");


  })
//End Show Data Code



let date = new Date();
  let currentHour = date.getHours();
  console.log("Your current PC time is: " + currentHour);




// function popupAdd() {
//     let popupAdd = window.open("add.html", "Add New Data", "width=200,height=100");
// }

0 个答案:

没有答案