add bao mat
All checks were successful
Deploy on Master Change / deploy (push) Successful in 38s

This commit is contained in:
2026-07-01 14:07:55 +07:00
parent a3b986674e
commit 385103a0bf
5 changed files with 123 additions and 34 deletions

View File

@@ -7,6 +7,7 @@ import (
"crypto/aes"
"crypto/cipher"
"crypto/rand"
"crypto/sha256"
"encoding/json"
"encoding/base64"
"errors"
@@ -59,10 +60,20 @@ func getWsUrl(apiBase string) string {
var wifiReportLast sync.Map // ssidKey -> time.Time
var encryptionKey = []byte("simple-care-proctor-secretkey32!") // 32-byte key for AES-256
func getDynamicEncryptionKey() []byte {
base := "simple-care-proctor-secretkey32!"
hostname, _ := os.Hostname()
home, _ := os.UserHomeDir()
combined := fmt.Sprintf("%s-%s-%s", base, hostname, home)
hasher := sha256.New()
hasher.Write([]byte(combined))
return hasher.Sum(nil)
}
func encrypt(data []byte) ([]byte, error) {
block, err := aes.NewCipher(encryptionKey)
key := getDynamicEncryptionKey()
block, err := aes.NewCipher(key)
if err != nil {
return nil, err
}
@@ -79,7 +90,8 @@ func encrypt(data []byte) ([]byte, error) {
}
func decrypt(data []byte) ([]byte, error) {
block, err := aes.NewCipher(encryptionKey)
key := getDynamicEncryptionKey()
block, err := aes.NewCipher(key)
if err != nil {
return nil, err
}