接口环境设置
This commit is contained in:
24
common/js/des.js
Normal file
24
common/js/des.js
Normal file
@@ -0,0 +1,24 @@
|
||||
import CryptoJS from '../js/crypto.js'
|
||||
|
||||
// DES加密
|
||||
export const encryptDes = (message, key) => {
|
||||
const keyHex = CryptoJS.enc.Utf8.parse(key);
|
||||
const encrypted = CryptoJS.DES.encrypt(message, keyHex, {
|
||||
mode: CryptoJS.mode.ECB,
|
||||
padding: CryptoJS.pad.Pkcs7
|
||||
});
|
||||
return encrypted.toString();
|
||||
}
|
||||
|
||||
// DES解密
|
||||
export const decryptDes = (ciphertext, key) => {
|
||||
const keyHex = CryptoJS.enc.Utf8.parse(key);
|
||||
// direct decrypt ciphertext
|
||||
const decrypted = CryptoJS.DES.decrypt({
|
||||
ciphertext: CryptoJS.enc.Base64.parse(ciphertext)
|
||||
}, keyHex, {
|
||||
mode: CryptoJS.mode.ECB,
|
||||
padding: CryptoJS.pad.Pkcs7
|
||||
});
|
||||
return decrypted.toString(CryptoJS.enc.Utf8);
|
||||
}
|
||||
Reference in New Issue
Block a user