mirror of
https://github.com/Macrame-App/Macrame
synced 2025-12-29 07:19:26 +00:00
Major update, devices view and components
The view for devices is functional now. It is possible to view, link and unlink devices and possible to gain access to authenticated endpoints with a key encrypted by a one time pin.
This commit is contained in:
parent
b598a090bc
commit
a01e026aa1
12 changed files with 1282 additions and 673 deletions
51
fe/src/services/EncryptService.js
Normal file
51
fe/src/services/EncryptService.js
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
import { useDeviceStore } from '@/stores/device'
|
||||
import { AES, enc, pad } from 'crypto-js'
|
||||
|
||||
export const encryptAES = (key, str) => {
|
||||
key = keyPad(key)
|
||||
|
||||
let iv = enc.Utf8.parse(import.meta.env.VITE_MCRM__IV)
|
||||
let encrypted = AES.encrypt(str, key, {
|
||||
iv: iv,
|
||||
padding: pad.Pkcs7,
|
||||
})
|
||||
return encrypted.toString()
|
||||
}
|
||||
|
||||
export const decryptAES = (key, str) => {
|
||||
key = keyPad(key)
|
||||
|
||||
let iv = enc.Utf8.parse(import.meta.env.VITE_MCRM__IV)
|
||||
let encrypted = AES.decrypt(str.toString(), key, {
|
||||
iv: iv,
|
||||
padding: pad.Pkcs7,
|
||||
})
|
||||
return encrypted.toString(enc.Utf8)
|
||||
}
|
||||
|
||||
export const AuthCall = (data) => {
|
||||
const device = useDeviceStore()
|
||||
|
||||
return {
|
||||
uuid: device.uuid(),
|
||||
d: encryptAES(device.key(), JSON.stringify(data)),
|
||||
}
|
||||
}
|
||||
|
||||
function keyPad(key) {
|
||||
let returnKey = key
|
||||
|
||||
if (key.length == 4) {
|
||||
returnKey = key + import.meta.env.VITE_MCRM__SALT
|
||||
}
|
||||
|
||||
return enc.Utf8.parse(returnKey)
|
||||
}
|
||||
|
||||
export const getDateStr = () => {
|
||||
const date = new Date()
|
||||
const year = date.getFullYear()
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0')
|
||||
const day = String(date.getDate()).padStart(2, '0')
|
||||
return `${year}${month}${day}`
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue