Skip to content

Commit

Permalink
build(dependencies): 替换 gm-crypto 为 jxk
Browse files Browse the repository at this point in the history
- 将 gm-crypto 包替换为 jxk 包,版本从 0.1.12 升级到 0.1.14
- 优化了加密解密功能,移除了不必要的错误处理和数据转换
- 删除了不再使用的 base64-js、buffer、ieee754、jsbn 和 to-arraybuffer 依赖
  • Loading branch information
xkloveme committed Nov 26, 2024
1 parent 8796b52 commit 49f4b64
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 60 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"preview": "vite preview"
},
"dependencies": {
"gm-crypto": "^0.1.12",
"jxk": "^0.1.12",
"hls.js": "^1.5.17",
"jsfuck": "^0.4.0",
"pinia": "2.1.0",
Expand Down
48 changes: 8 additions & 40 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 11 additions & 19 deletions src/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,28 @@
import { SM4 } from 'gm-crypto'
import { sm4 } from 'jxk'
import {userStore} from '../store/user'
// const store = userStore()
// sm4对字符串加密
export function encrypt(originalData) {
const { SM4Key } = userStore()
if (originalData === '' || originalData === null || originalData === undefined)
return originalData
if (originalData === '' || originalData === null || originalData === undefined) {
return originalData;
}
try {
return SM4.encrypt(originalData + '', SM4Key, {
inputEncoding: 'utf8',
outputEncoding: 'hex',
})
return SM4Key ? sm4.encrypt(originalData + '', SM4Key) : originalData;
} catch (error) {
console.error('🐛: ~ encrypt ~ error:', originalData, error)
return originalData;
}
}

// sm4对字符串解密
export function decrypt(encryptedData) {
const { SM4Key } = userStore()
if (encryptedData === '' || encryptedData === null || encryptedData === undefined) {
return encryptedData;
}
try {
const decryptedData = SM4.decrypt(encryptedData, SM4Key, {
inputEncoding: 'hex',
outputEncoding: 'utf8',
})
console.log("===🐛=== ~ decrypt ~ decryptedData:", decryptedData);
try {
return JSON.stringify(JSON.parse(decryptedData), null, '\t')
} catch (error) {
return decryptedData
}
return SM4Key ? sm4.decrypt(encryptedData, SM4Key) : encryptedData;
} catch (error) {
return encryptedData
return encryptedData;
}
}

0 comments on commit 49f4b64

Please sign in to comment.