2023-11-09 07:34:00 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"crypto/ecdh"
|
|
|
|
|
|
|
|
|
|
"github.com/AYM1607/ccclip/pkg/api"
|
|
|
|
|
"github.com/AYM1607/ccclip/pkg/crypto"
|
|
|
|
|
)
|
|
|
|
|
|
2023-11-10 17:01:28 +00:00
|
|
|
func encryptForAll(plaintext []byte, pvk *ecdh.PrivateKey, devices []*api.Device) map[string][]byte {
|
2023-11-09 07:34:00 +00:00
|
|
|
res := map[string][]byte{}
|
|
|
|
|
for _, d := range devices {
|
|
|
|
|
key := crypto.NewSharedKey(pvk, crypto.PublicKeyFromBytes(d.PublicKey), crypto.SendDirection)
|
2023-11-10 17:01:28 +00:00
|
|
|
res[d.ID] = crypto.Encrypt(key, plaintext)
|
2023-11-09 07:34:00 +00:00
|
|
|
}
|
|
|
|
|
return res
|
|
|
|
|
}
|