From ed2ce0952aa9a9c30407e3084c7d24068ec53575 Mon Sep 17 00:00:00 2001 From: binbin_pan Date: Fri, 24 May 2024 19:08:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=86=E7=A0=81=E6=98=8E=E6=96=87=E5=8A=A0?= =?UTF-8?q?=E5=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sgzb-ui/src/store/modules/user.js | 35 +++---------------------------- sgzb-ui/src/utils/jsencrypt.js | 12 ++--------- 2 files changed, 5 insertions(+), 42 deletions(-) diff --git a/sgzb-ui/src/store/modules/user.js b/sgzb-ui/src/store/modules/user.js index 230569b0..b95b8d04 100644 --- a/sgzb-ui/src/store/modules/user.js +++ b/sgzb-ui/src/store/modules/user.js @@ -1,36 +1,7 @@ import { login, logout, getInfo, refreshToken,checkCode,loginByMall } from '@/api/login' import { getToken, setToken, setExpiresIn, removeToken } from '@/utils/auth' import { Notification, MessageBox, Message, Loading } from 'element-ui' - -const secretKey = 'CCNWrpassWordKey' - -async function encryptData(data, keyStr) { - try { - const keyUint8 = new TextEncoder().encode(keyStr); - const key = await crypto.subtle.importKey( - 'raw', - keyUint8, - { name: 'AES-CBC', length: 256 }, - false, - ['encrypt'] - ); - - const iv = crypto.getRandomValues(new Uint8Array(16)); - const cipherTextBuffer = await crypto.subtle.encrypt( - { name: 'AES-CBC', iv }, - key, - new TextEncoder().encode(data) - ); - - const combined = new Uint8Array(iv.length + cipherTextBuffer.byteLength); - combined.set(iv, 0); - combined.set(new Uint8Array(cipherTextBuffer), iv.length); - - return btoa(String.fromCharCode.apply(null, combined)); - } catch (error) { - console.log('🚀 ~ encryptData ~ error:', error); - } -} +import { encrypt} from '@/utils/jsencrypt' const user = { state: { @@ -68,9 +39,9 @@ const user = { actions: { // 登录 - async Login({ commit }, userInfo) { + Login({ commit }, userInfo) { const username = userInfo.username.trim() - const password = await encryptData(userInfo.password, secretKey); + const password = encrypt(userInfo.password) const code = userInfo.code const uuid = userInfo.uuid return new Promise((resolve, reject) => { diff --git a/sgzb-ui/src/utils/jsencrypt.js b/sgzb-ui/src/utils/jsencrypt.js index 78d95234..19b70dac 100644 --- a/sgzb-ui/src/utils/jsencrypt.js +++ b/sgzb-ui/src/utils/jsencrypt.js @@ -2,17 +2,9 @@ import JSEncrypt from 'jsencrypt/bin/jsencrypt.min' // 密钥对生成 http://web.chacuo.net/netrsakeypair -const publicKey = 'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKoR8mX0rGKLqzcWmOzbfj64K8ZIgOdH\n' + - 'nzkXSOVOZbFu/TJhZ7rFAN+eaGkl3C4buccQd/EjEsj9ir7ijT7h96MCAwEAAQ==' +const publicKey = 'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKoR8mX0rGKLqzcWmOzbfj64K8ZIgOdHnzkXSOVOZbFu/TJhZ7rFAN+eaGkl3C4buccQd/EjEsj9ir7ijT7h96MCAwEAAQ==' -const privateKey = 'MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAqhHyZfSsYourNxaY\n' + - '7Nt+PrgrxkiA50efORdI5U5lsW79MmFnusUA355oaSXcLhu5xxB38SMSyP2KvuKN\n' + - 'PuH3owIDAQABAkAfoiLyL+Z4lf4Myxk6xUDgLaWGximj20CUf+5BKKnlrK+Ed8gA\n' + - 'kM0HqoTt2UZwA5E2MzS4EI2gjfQhz5X28uqxAiEA3wNFxfrCZlSZHb0gn2zDpWow\n' + - 'cSxQAgiCstxGUoOqlW8CIQDDOerGKH5OmCJ4Z21v+F25WaHYPxCFMvwxpcw99Ecv\n' + - 'DQIgIdhDTIqD2jfYjPTY8Jj3EDGPbH2HHuffvflECt3Ek60CIQCFRlCkHpi7hthh\n' + - 'YhovyloRYsM+IS9h/0BzlEAuO0ktMQIgSPT3aFAgJYwKpqRYKlLDVcflZFCKY7u3\n' + - 'UP8iWi1Qw0Y=' +const privateKey = 'MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAqhHyZfSsYourNxaY7Nt+PrgrxkiA50efORdI5U5lsW79MmFnusUA355oaSXcLhu5xxB38SMSyP2KvuKNPuH3owIDAQABAkAfoiLyL+Z4lf4Myxk6xUDgLaWGximj20CUf+5BKKnlrK+Ed8gAkM0HqoTt2UZwA5E2MzS4EI2gjfQhz5X28uqxAiEA3wNFxfrCZlSZHb0gn2zDpWowcSxQAgiCstxGUoOqlW8CIQDDOerGKH5OmCJ4Z21v+F25WaHYPxCFMvwxpcw99EcvDQIgIdhDTIqD2jfYjPTY8Jj3EDGPbH2HHuffvflECt3Ek60CIQCFRlCkHpi7hthhYhovyloRYsM+IS9h/0BzlEAuO0ktMQIgSPT3aFAgJYwKpqRYKlLDVcflZFCKY7u3UP8iWi1Qw0Y=' // 加密 export function encrypt(txt) {