Table: RailsNotes
User: dreamable
Created at: 2021-04-10 08:24:53 UTC
Updated at: 2021-04-10 19:42:29 UTC
Reference:(Table ID 3, Record ID 36)

标题 :
JavaScript string encryption and decryption?
笔记 :

Guide

crypto-js

  • install
yarn add crypto-js
  • javascript/packs/application.js
var CryptoJS = require("crypto-js");
$(document).on("turbolinks:load", function() {
  console.log("DEBUG:: turbolinks.load!")
  var encrypted = CryptoJS.AES.encrypt("加密Message", "Secret Passphrase");
  var decrypted = CryptoJS.AES.decrypt(encrypted, "Secret Passphrase");
  var plaintext = decrypted.toString(CryptoJS.enc.Utf8);
  $("#demo1").text(encrypted)
  $("#demo2").text(decrypted)
  $("#demo3").text(plaintext)
});
  • html
<br>
<label>encrypted</label>
<div id="demo1"></div>
<br>

<label>decrypted</label>
<div id="demo2"></div>

<br>
<label>Actual Message</label>
<div id="demo3"></div>
Tag: