f
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import CryptoJS from 'crypto-js'
|
||||
|
||||
/** 与 tyc-webview-v2 `utils/crypto.js` 一致:AES-CBC,IV 前置后 Base64 */
|
||||
export function aesEncrypt(plainText: string, hexKey: string): string {
|
||||
export function aesEncrypt(plainText, hexKey) {
|
||||
const key = CryptoJS.enc.Hex.parse(hexKey)
|
||||
const iv = generateRandomIV()
|
||||
const encrypted = CryptoJS.AES.encrypt(plainText, key, {
|
||||
@@ -14,7 +14,7 @@ export function aesEncrypt(plainText: string, hexKey: string): string {
|
||||
}
|
||||
|
||||
function generateRandomIV() {
|
||||
const iv: number[] = []
|
||||
const iv = []
|
||||
for (let i = 0; i < 16; i++)
|
||||
iv.push(Math.floor(Math.random() * 256))
|
||||
return CryptoJS.enc.Hex.parse(iv.map(b => b.toString(16).padStart(2, '0')).join(''))
|
||||
Reference in New Issue
Block a user