解密初始密码

This commit is contained in:
binbin_pan 2024-06-04 14:05:26 +08:00
parent 3be3330714
commit d02a155852
1 changed files with 2 additions and 57 deletions

View File

@ -551,6 +551,7 @@ import { getToken } from '@/utils/auth'
import Treeselect from '@riophae/vue-treeselect'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
import { validPassword } from '@/utils/validate'
import { decrypt } from '@/utils/jsencrypt.js'
export default {
name: 'User',
@ -714,14 +715,7 @@ export default {
this.getList()
this.getDeptTree()
this.getConfigKey('sys.user.initPassword').then((response) => {
this.decryptData(response.msg, this.secretKey)
.then((data) => {
console.log('🚀 ~ this.getConfigKey ~ data:', data)
this.initPassword = data
})
.catch((error) => {
console.log('🚀 ~ this.getConfigKey ~ error:', error)
})
this.initPassword = decrypt(response.msg)
})
},
methods: {
@ -962,55 +956,6 @@ export default {
submitFileForm() {
this.$refs.upload.submit()
},
//
async encryptData(data, keyStr) {
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))
},
//
async decryptData(encryptedData, keyStr) {
const keyUint8 = new TextEncoder().encode(keyStr)
const encryptedBytes = Uint8Array.from(atob(encryptedData), (c) =>
c.charCodeAt(0),
)
const key = await crypto.subtle.importKey(
'raw',
keyUint8,
{ name: 'AES-CBC', length: 256 }, // 使CBC使
false,
['decrypt'],
)
const decryptedData = await crypto.subtle.decrypt(
{ name: 'AES-CBC', iv: new Uint8Array(16) }, // 使IV
key,
encryptedBytes,
)
return new TextDecoder().decode(decryptedData)
},
},
}
</script>