-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c21ffb9
commit abb54ab
Showing
6 changed files
with
84 additions
and
4 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
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
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 +1,2 @@ | ||
export { default as logger } from './logger'; | ||
export { decrypt, encrypt } from './secret'; |
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import CryptoJS from 'crypto-js'; | ||
const aseKey = '0123456789abcdef'; | ||
const iv = 'abcdef0123456789'; | ||
let key = CryptoJS.enc.Utf8.parse(aseKey); | ||
let ivs = CryptoJS.enc.Utf8.parse(iv); | ||
|
||
//加密 | ||
export function encrypt(data: any) { | ||
let encrypted = CryptoJS.AES.encrypt(data, key, { | ||
iv: ivs, | ||
mode: CryptoJS.mode.CBC, | ||
padding: CryptoJS.pad.Pkcs7, | ||
}); | ||
return encrypted.toString(); | ||
} | ||
|
||
//解密 | ||
export function decrypt(data: any) { | ||
let decrypt = CryptoJS.AES.decrypt(data, key, { | ||
iv: ivs, | ||
mode: CryptoJS.mode.CBC, | ||
padding: CryptoJS.pad.Pkcs7, | ||
}); | ||
return CryptoJS.enc.Utf8.stringify(decrypt).toString(); | ||
} | ||
|
||
export default { | ||
encrypt, | ||
decrypt, | ||
}; |