Compare commits
2 Commits
d2f010d6f1
...
2fb35a89d2
Author | SHA1 | Date |
---|---|---|
|
2fb35a89d2 | 1 year ago |
|
2e29e365e6 | 1 year ago |
4 changed files with 77 additions and 2 deletions
@ -0,0 +1,67 @@ |
||||
/** |
||||
* Aes加解密 |
||||
* aec1b4218112932c |
||||
* b0e8d4dbaff1ed30 |
||||
* ec241d54487cabf8 |
||||
* f768a3dc18069961 |
||||
* 620b8d3c3be1e725 |
||||
*/ |
||||
|
||||
const aesKey = '620b8d3c3be1e725' |
||||
const crypto = require('crypto-js') |
||||
const key = crypto.enc.Utf8.parse(aesKey) |
||||
|
||||
/** |
||||
* 加密,解密工具类 |
||||
*/ |
||||
function encrypt(word) { |
||||
var srcs = crypto.enc.Utf8.parse(word) |
||||
var encrypted = crypto.AES.encrypt(srcs, key, { |
||||
mode: crypto.mode.ECB, |
||||
padding: crypto.pad.Pkcs7 |
||||
}) |
||||
return encrypted.toString() |
||||
// return strToHex(encrypted.toString());
|
||||
} |
||||
|
||||
function decrypt(word) { |
||||
//word = hexToStr(word);
|
||||
var decrypt = crypto.AES.decrypt(word, key, { |
||||
mode: crypto.mode.ECB, |
||||
padding: crypto.pad.Pkcs7 |
||||
}) |
||||
|
||||
return crypto.enc.Utf8.stringify(decrypt).toString() |
||||
} |
||||
|
||||
function strToHex(str) { |
||||
var val = '' |
||||
for (var i = 0; i < str.length; i++) { |
||||
if (val == '') { |
||||
val = str.charCodeAt(i).toString(16) |
||||
} else { |
||||
val += str.charCodeAt(i).toString(16) |
||||
} |
||||
} |
||||
val += '0a' |
||||
return val |
||||
} |
||||
|
||||
function hexToStr(hex) { |
||||
debugger; |
||||
//hex = JSON.stringify(hex);
|
||||
hex = hex + '' |
||||
var arr = hex.split('') |
||||
var out = '' |
||||
for (var i = 0; i < arr.length / 2; i++) { |
||||
var tmp = '0x' + arr[i * 2] + arr[i * 2 + 1] |
||||
var charValue = String.fromCharCode(tmp) |
||||
out += charValue |
||||
} |
||||
return out |
||||
} |
||||
|
||||
export default { |
||||
decrypt, |
||||
encrypt, |
||||
} |
Loading…
Reference in new issue