-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build(dependencies): 替换 gm-crypto 为 jxk
- 将 gm-crypto 包替换为 jxk 包,版本从 0.1.12 升级到 0.1.14 - 优化了加密解密功能,移除了不必要的错误处理和数据转换 - 删除了不再使用的 base64-js、buffer、ieee754、jsbn 和 to-arraybuffer 依赖
- Loading branch information
Showing
3 changed files
with
20 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |