crypto-js
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)
});
<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>