fix: 修改数据加密解密,新增登录校验,新增底部备案号

This commit is contained in:
奔跑的面条
2022-04-13 21:31:18 +08:00
parent 77a6b50307
commit efba045ad0
9 changed files with 110 additions and 51 deletions
+24 -19
View File
@@ -1,29 +1,34 @@
import * as CryptoJS from 'crypto-ts'
// 加密
const AES_KEY = 'mt'
import CryptoJS from 'crypto-js'
import { isString } from './type'
const KEY = 'mt'
/**
* * 加密
* @param data { string }
* @returns
*/
export const cryptoEncode = (data: string): string => {
if (typeof data !== 'string') return ''
if (!isString(data)) return ''
// 加密
const key = CryptoJS.enc.Utf8.parse(AES_KEY)
const str = JSON.stringify(data)
const encryptedData = CryptoJS.AES.encrypt(str, key, {
const encryptedData = CryptoJS.AES.encrypt(data, KEY, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.PKCS7,
iv: CryptoJS.enc.Utf8.parse(AES_KEY)
})
return encryptedData.toString()
padding: CryptoJS.pad.Pkcs7
}).toString()
return encryptedData
}
// 解密
/**
* * 解密
* @param data { string }
* @returns
*/
export const cryptoDecode = (data: string): string => {
if (typeof data !== 'string') return ''
const encryptedHexStr = CryptoJS.enc.Utf8.parse(data)
const encryptedBase64Str = CryptoJS.enc.Utf8.stringify(encryptedHexStr)
const key = CryptoJS.enc.Utf8.parse(AES_KEY)
const decryptedData = CryptoJS.AES.decrypt(encryptedBase64Str, key, {
if (!isString(data)) return ''
// 解密
const decryptedData = CryptoJS.AES.decrypt(data, KEY, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.PKCS7,
iv: CryptoJS.enc.Utf8.parse(AES_KEY)
padding: CryptoJS.pad.Pkcs7
})
return decryptedData.toString(CryptoJS.enc.Utf8)
}