解密初始密码
This commit is contained in:
parent
a14014831a
commit
bc2ee69dd7
|
|
@ -429,7 +429,7 @@ import { getToken } from '@/utils/auth'
|
||||||
import Treeselect from '@riophae/vue-treeselect'
|
import Treeselect from '@riophae/vue-treeselect'
|
||||||
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
|
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
|
||||||
import { validPassword } from '@/utils/validate'
|
import { validPassword } from '@/utils/validate'
|
||||||
import { encrypt } from '@/utils/jsencrypt'
|
import { decrypt } from '@/utils/jsencrypt'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'User',
|
name: 'User',
|
||||||
|
|
@ -588,7 +588,7 @@ export default {
|
||||||
this.getList()
|
this.getList()
|
||||||
this.getDeptTree()
|
this.getDeptTree()
|
||||||
this.getConfigKey('sys.user.initPassword').then(response => {
|
this.getConfigKey('sys.user.initPassword').then(response => {
|
||||||
this.initPassword = encrypt(response.msg)
|
this.initPassword = decrypt(response.msg)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
|
@ -821,41 +821,6 @@ export default {
|
||||||
submitFileForm() {
|
submitFileForm() {
|
||||||
this.$refs.upload.submit()
|
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>
|
</script>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue