s4decrypt.html 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <!DOCTYPE html>
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  5. <title>解密</title>
  6. <link href="AFrontEnd/css/special.css" rel="stylesheet" />
  7. </head>
  8. <body class="sp-page-center" onkeydown="keyLogin();">
  9. <div class="sp-box" style="line-height: 30px">
  10. <div class="sp-page" style="width: 10%;">加密内容:</div>
  11. <textarea style="width: 80%; resize: none; " rows="10" class="sp-textarea" id="content1"></textarea>
  12. <div class="sp-page sp-pull-right" style="width: 10%;"><button class="sp-btn-blue" onclick="decrypt()">解密</button></div>
  13. </div>
  14. <div class="sp-box" style="line-height: 30px">
  15. <div class="sp-page" style="width: 10%;">解密内容:</div>
  16. <textarea style="width: 80%; resize: none; " rows="10" class="sp-textarea" id="content2"></textarea>
  17. <div class="sp-page sp-pull-right" style="width: 10%;"><button class="sp-btn-blue" onclick="encrypt()">加密</button></div>
  18. </div>
  19. <script src="AFrontEnd/js/jquery/jquery-1.8.3.min.js"></script>
  20. <script src="js/sm4.js"></script>
  21. <script>
  22. var s4 = new SM4Util();
  23. function keyLogin() {
  24. if (event.keyCode == 13) //回车键的键值为13
  25. {
  26. if ($("#content1").val() != "") {
  27. decrypt();
  28. } else {
  29. encrypt();
  30. }
  31. }
  32. }
  33. function encrypt() {
  34. var content = $("#content2").val()
  35. $("#content1").val(s4.encryptData_CBC(content))
  36. }
  37. function decrypt() {
  38. var time1 = new Date().getTime();
  39. console.log(time1)
  40. var content = $("#content1").val().replace(/"+/g, "").replace(/\s+/g, "");
  41. var data = s4.decryptData_CBC(content).replace(/\u0000|\u0001|\u0002|\u0003|\u0004|\u0005|\u0006|\u0007|\u0008|\u0009|\u000a|\u000b|\u000c|\u000d|\u000e|\u000f|\u0010|\u0011|\u0012|\u0013|\u0014|\u0015|\u0016|\u0017|\u0018|\u0019|\u001a|\u001b|\u001c|\u001d|\u001e|\u001f|\u007F/g, "")
  42. $("#content2").val(data)
  43. console.log(JSON.parse(data))
  44. console.log(new Date().getTime() - time1)
  45. }
  46. var n = 0;
  47. document.addEventListener("visibilitychange", function () {
  48. if (document.visibilityState == "visible") {
  49. n++
  50. //console.log("s4decrypt.html" + n)
  51. }
  52. })
  53. sessionStorage.setItem("operate",0)
  54. var mytime = setTimeout("Timeout()", 6000);
  55. function resetTime() {
  56. n = 0;
  57. clearTimeout(mytime);
  58. mytime = setTimeout("Timeout()", 6000);
  59. }
  60. function Timeout() {
  61. //alert("登录超时!")
  62. }
  63. var n = 0;
  64. setInterval(function () {
  65. n = n + 1;
  66. //console.log(n)
  67. if (sessionStorage.getItem("operate") == 1) {
  68. sessionStorage.setItem("operate", 0)
  69. resetTime()
  70. }
  71. },1000)
  72. document.documentElement.onkeydown = function () { sessionStorage.setItem("operate", 1) };
  73. document.documentElement.onmousemove = function () { sessionStorage.setItem("operate", 1) };
  74. document.documentElement.onmousedown = function () { sessionStorage.setItem("operate", 1) };
  75. </script>
  76. </body>
  77. </html>