Skip to content

Commit

Permalink
Merge pull request #75 from vusion/task-2820863925175808-cw_cryptojs_…
Browse files Browse the repository at this point in the history
…library-hanshijie-240312

feat: 新增des解密方法。
  • Loading branch information
ncqwer authored Mar 12, 2024
2 parents 9f70734 + 7f42695 commit 2276272
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 1 deletion.
8 changes: 8 additions & 0 deletions packages/cw/cw_cryptojs_library/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 1.0.3

Associated Task: [#282086](https://projectmanage.netease-official.lcap.163yun.com/dashboard/TaskDetail?id=2820863925175808)

### ✨Features

- [ca8029f](https://github.com/vusion/cloud-ui-materials/commit/ca8029f1b020477023394372edf57d139705da35) Thanks [ncqwer](https://github.com/ncqwer) ! - 新增des解密方法。

## 1.0.2

Associated Task: [#281727](https://projectmanage.netease-official.lcap.163yun.com/dashboard/TaskDetail?id=2817277092559616)
Expand Down
5 changes: 5 additions & 0 deletions packages/cw/cw_cryptojs_library/logics/decryptByDes/api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- name: decryptByDes
description: Des解密
type: both
belong: logic
labels: [Runtime]
44 changes: 44 additions & 0 deletions packages/cw/cw_cryptojs_library/logics/decryptByDes/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* @param {string} data <true> 需要解密的内容
* @param {string} key <true> 加密的key
* @param {string} iv <true> 加密的iv
* @returns {string} result
*/
import CryptoJS from 'crypto-js';
export default (data, key, iv) => {
function hex2str(hex) {
if (!hex) {
return '';
}
let trimedStr = hex.trim();
let rawStr =
trimedStr.substr(0, 2).toLowerCase() === '0x'
? trimedStr.substr(2)
: trimedStr;
let len = rawStr.length;
if (len % 2 !== 0) {
alert('非法格式的ASCII代码!');
return '';
}
let curCharCode;
let resultStr = [];
for (let i = 0; i < len; i = i + 2) {
curCharCode = parseInt(rawStr.substr(i, 2), 16);
resultStr.push(String.fromCharCode(curCharCode));
}
return resultStr.join('');
}
if (data === undefined) {
return data;
}
// console.log(CryptoJS);
const keyHex = CryptoJS.enc.Utf8.parse(hex2str(key));
const ivHex = CryptoJS.enc.Utf8.parse(hex2str(iv));
const decrypted = CryptoJS.TripleDES.decrypt(data, keyHex, {
iv: ivHex,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7,
});
return decrypted.toString(CryptoJS.enc.Utf8);
// TODO
};
2 changes: 2 additions & 0 deletions packages/cw/cw_cryptojs_library/logics/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import encryptSha256 from './encryptSha256'
import encryptDataWithSalt from './encryptDataWithSalt'
import decryptDataWithSalt from './decryptDataWithSalt'
import base64Withsjcl from './base64Withsjcl'
import decryptByDes from './decryptByDes'
// LOGIC IMPORTS
UtilsLogics.install = function (Vue, option = {}) {
Vue.prototype.$library = Vue.prototype.$library || {}
Expand All @@ -15,6 +16,7 @@ UtilsLogics.install = function (Vue, option = {}) {
Vue.prototype.$library[`${$libraryName}`].encryptDataWithSalt=encryptDataWithSalt
Vue.prototype.$library[`${$libraryName}`].decryptDataWithSalt=decryptDataWithSalt
Vue.prototype.$library[`${$libraryName}`].base64Withsjcl=base64Withsjcl
Vue.prototype.$library[`${$libraryName}`].decryptByDes=decryptByDes
// LOGIC USE
window.__$libraryEncryptSha256 = encryptSha256
}
Expand Down
2 changes: 1 addition & 1 deletion packages/cw/cw_cryptojs_library/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "cw_cryptojs_library",
"title": "前端加密依赖库",
"description": "",
"version": "1.0.2",
"version": "1.0.3",
"main": "./index.js",
"author": "",
"repository": "",
Expand Down

0 comments on commit 2276272

Please sign in to comment.