一个分享WordPress、Zblog、Emlog、Typecho等主流博客的教程网站!
当前位置:网站首页 > 编程知识 > 正文

微信小程序常见json解密方法crypto-js

作者:xlnxin发布时间:2026-09-25分类:编程知识浏览:335


导读:微信小程序index.jsvar e = require("./secret.js")Page({  ...

微信小程序index.js

var e = require("./secret.js")
Page({
  data: {
    json: []
  },
  onLoad() {
    var that = this
    wx.request({
      url: "https://www.获取网址.com/加密的json文件.json",
      method: 'GET',
      header: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        that.setData({
          json: e.Decrypt(res.data)
          //解密小程序json文件内容
        })
      },
      fail: function (err) {
        console.log(err)
      }
    })
  },
  // js
handleCopy(e) {
  wx.setClipboardData({
    data: this.data.json,
    success: function() {
      wx.showToast({ title: '复制成功' });
    }
  });
}
})

index.wxml

<view bind:tap="handleCopy">{{json}}</view>
/*点击复制json解密代码*/

secret.js

 exports.Decrypt = function(c) {
  var n = e.enc.Base64.parse(c),
    s = e.enc.Base64.stringify(n),
    d = e.AES.decrypt(s, r, {
      iv: t,
      mode: e.mode.CBC,
      padding: e.pad.Pkcs7
    });
  return e.enc.Utf8.stringify(d)
}, exports.Encrypt = function(c) {
  var n = e.enc.Utf8.parse(c),
    s = e.AES.encrypt(n, r, {
      iv: t,
      mode: e.mode.CBC,
      padding: e.pad.Pkcs7
    });
  return e.enc.Base64.stringify(s.ciphertext)
};
var e = require("./crypto-js.js"),
  r = e.enc.Utf8.parse("7dfd6c19dcdd4668"),
  t = e.enc.Utf8.parse("ad4fbf313c3c4bc7");

typeof.js

function _typeof(o) {
  return module.exports = _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
    return typeof o
  } : function(o) {
    return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o
  }, _typeof(o)
}
module.exports = _typeof;

crypto-js.js自行下载。

标签:程序小程序js