Browse Source

解密

master
kola-web 2 months ago
parent
commit
7a285c08e2
  1. 1
      package.json
  2. 8
      pnpm-lock.yaml
  3. 128
      project.config.json
  4. 12
      src/app.ts
  5. 7365
      src/miniprogram_npm/crypto-js/index.js
  6. 4
      src/miniprogram_npm/dayjs/index.js
  7. 2
      src/pages/article/index.ts
  8. 34
      src/utils/crypto.ts

1
package.json

@ -10,6 +10,7 @@ @@ -10,6 +10,7 @@
},
"dependencies": {
"@vant/weapp": "^1.11.6",
"crypto-js": "^4.2.0",
"dayjs": "^1.11.13",
"miniprogram-licia": "^1.39.2",
"mp-html": "^2.5.0",

8
pnpm-lock.yaml

@ -11,6 +11,9 @@ importers: @@ -11,6 +11,9 @@ importers:
'@vant/weapp':
specifier: ^1.11.6
version: 1.11.6
crypto-js:
specifier: ^4.2.0
version: 4.2.0
dayjs:
specifier: ^1.11.13
version: 1.11.13
@ -462,6 +465,9 @@ packages: @@ -462,6 +465,9 @@ packages:
resolution: {integrity: sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==}
engines: {node: '>= 8'}
crypto-js@4.2.0:
resolution: {integrity: sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q==}
cssesc@3.0.0:
resolution: {integrity: sha512-/Tb/JcjK111nNScGob5MNtsntNM1aCNUDipB/TkwZFhyDrrE47SOx/18wF2bbjgc3ZzCSKW1T5nt5EbFoAz/Vg==}
engines: {node: '>=4'}
@ -1929,6 +1935,8 @@ snapshots: @@ -1929,6 +1935,8 @@ snapshots:
shebang-command: 2.0.0
which: 2.0.2
crypto-js@4.2.0: {}
cssesc@3.0.0: {}
dayjs@1.11.13: {}

128
project.config.json

@ -1,65 +1,65 @@ @@ -1,65 +1,65 @@
{
"description": "项目配置文件",
"miniprogramRoot": "src/",
"compileType": "miniprogram",
"setting": {
"useCompilerPlugins": [
"typescript",
"sass"
],
"babelSetting": {
"ignore": [],
"disablePlugins": [],
"outputPath": ""
},
"coverView": false,
"postcss": false,
"minified": false,
"enhance": true,
"showShadowRootInWxmlPanel": false,
"packNpmManually": true,
"packNpmRelationList": [
{
"packageJsonPath": "package.json",
"miniprogramNpmDistDir": "./src"
}
],
"ignoreUploadUnusedFiles": true,
"compileHotReLoad": false,
"skylineRenderEnable": true,
"es6": true
},
"simulatorType": "wechat",
"simulatorPluginLibVersion": {},
"condition": {},
"srcMiniprogramRoot": "src/",
"editorSetting": {
"tabIndent": "insertSpaces",
"tabSize": 2
},
"libVersion": "2.32.3",
"ignore": [],
"packOptions": {
"ignore": [
{
"value": "src/images/*.*",
"type": "glob"
},
{
"value": "src/images/**/*.*",
"type": "glob"
},
{
"value": "src/images/**/**/*.*",
"type": "glob"
}
],
"include": [
{
"value": "src/images/tabbar/*.*",
"type": "glob"
}
]
},
"appid": "wxa4a28b299df7d921"
{
"description": "项目配置文件",
"miniprogramRoot": "src/",
"compileType": "miniprogram",
"setting": {
"useCompilerPlugins": [
"typescript",
"sass"
],
"babelSetting": {
"ignore": [],
"disablePlugins": [],
"outputPath": ""
},
"coverView": false,
"postcss": false,
"minified": false,
"enhance": true,
"showShadowRootInWxmlPanel": false,
"packNpmManually": true,
"packNpmRelationList": [
{
"packageJsonPath": "package.json",
"miniprogramNpmDistDir": "./src"
}
],
"ignoreUploadUnusedFiles": true,
"compileHotReLoad": false,
"skylineRenderEnable": true,
"es6": true
},
"simulatorType": "wechat",
"simulatorPluginLibVersion": {},
"condition": {},
"srcMiniprogramRoot": "src/",
"editorSetting": {
"tabIndent": "insertSpaces",
"tabSize": 2
},
"libVersion": "2.32.3",
"ignore": [],
"packOptions": {
"ignore": [
{
"value": "src/images/*.*",
"type": "glob"
},
{
"value": "src/images/**/*.*",
"type": "glob"
},
{
"value": "src/images/**/**/*.*",
"type": "glob"
}
],
"include": [
{
"value": "src/images/tabbar/*.*",
"type": "glob"
}
]
},
"appid": "wxbdf6f933281b1eb4"
}

12
src/app.ts

@ -17,14 +17,14 @@ App<IAppOption>({ @@ -17,14 +17,14 @@ App<IAppOption>({
// 测试号 wx2b0bb13edf717c1d
// dev
// appid:wxbdf6f933281b1eb4
// url: 'https://m.shizhong.hbraas.com',
// upFileUrl: 'https://m.shizhong.hbraas.com/',
// imageUrl: 'https://m.shizhong.hbraas.com/api/shizhong/',
url: 'https://m.shizhong.hbraas.com',
upFileUrl: 'https://m.shizhong.hbraas.com/',
imageUrl: 'https://m.shizhong.hbraas.com/api/shizhong/',
// pro
// appid:wxa4a28b299df7d921
url: 'https://m.shizhong.hbsaas.com',
upFileUrl: 'https://m.shizhong.hbsaas.com/',
imageUrl: 'https://m.shizhong.hbsaas.com/api/shizhong/',
// url: 'https://m.shizhong.hbsaas.com',
// upFileUrl: 'https://m.shizhong.hbsaas.com/',
// imageUrl: 'https://m.shizhong.hbsaas.com/api/shizhong/',
loginState: '',
isLogin: 0,

7365
src/miniprogram_npm/crypto-js/index.js

File diff suppressed because it is too large Load Diff

4
src/miniprogram_npm/dayjs/index.js

File diff suppressed because one or more lines are too long

2
src/pages/article/index.ts

@ -1,3 +1,4 @@ @@ -1,3 +1,4 @@
import { decryptData } from '@/utils/crypto';
const app = getApp<IAppOption>();
Page({
@ -67,6 +68,7 @@ Page({ @@ -67,6 +68,7 @@ Page({
showMsg: false,
})
.then((res) => {
res.chapter.Content = decryptData(res.chapter.Content);
this.setData({
book: {
...res.book,

34
src/utils/crypto.ts

@ -0,0 +1,34 @@ @@ -0,0 +1,34 @@
import CryptoJS from 'crypto-js';
// 使用密钥长度128的RIJNDAEL算法解码数据,加密模式:ECB
const key = 'hbsaas1mobile2a6f8';
// 解密函数
export function decryptData(encryptedData) {
// Step 1: 替换 base64 字符中的 "+" 和 "/" 为 URL 安全的字符
encryptedData = encryptedData.replace(/-/g, '+').replace(/_/g, '/');
// Step 2: 解码 base64 数据
const decodedData = CryptoJS.enc.Base64.parse(encryptedData);
// Step 3: 填充 key,确保它的长度为 24 字节(128 位)
let paddedKey = key;
const keyLength = paddedKey.length;
if (keyLength < 24) {
paddedKey = paddedKey.padEnd(24, '\0'); // 用零填充至 16 字节
}
// Step 4: 使用 AES ECB 模式解密
const decryptedData = CryptoJS.AES.decrypt({ ciphertext: decodedData }, CryptoJS.enc.Utf8.parse(paddedKey), {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7, // 与 PHP 中的 PKCS5 padding 对应
});
// Step 5: 转换解密结果为明文字符串
return decryptedData.toString(CryptoJS.enc.Utf8);
}
// 示例使用:
// const encryptedData = "6QUbssj247RF6oIMf9nqT6F5LoYpAkFENy5wc572gws"; // 从 PHP 获取的加密数据
// const decrypted = decryptData(encryptedData, key);
// console.log(decrypted); // 输出解密后的数据
Loading…
Cancel
Save