MCPcopy Create free account
hub / github.com/daodst/chat / Encode

Function Encode

new_feature/key_func.go:42–52  ·  view source on GitHub ↗

Encode eciesPublicKey

(eciesPublicKey string, msg []byte)

Source from the content-addressed store, hash-verified

40
41// Encode eciesPublicKey
42func Encode(eciesPublicKey string, msg []byte) ([]byte, error) {
43 pukByte, err := base64.StdEncoding.DecodeString(eciesPublicKey)
44 if err != nil {
45 return []byte{}, err
46 }
47 pukInterface, err := x509.ParsePKIXPublicKey(pukByte)
48 ecdsaPubKey := pukInterface.(*ecdsa.PublicKey)
49 eciesPubKey := ecies.ImportECDSAPublic(ecdsaPubKey)
50
51 return ECCEncrypt(msg, *eciesPubKey)
52}
53func ECCEncrypt(pt []byte, puk ecies.PublicKey) ([]byte, error) {
54 ct, err := ecies.Encrypt(rand.Reader, &puk, pt, nil, nil)
55 return ct, err

Callers 1

TestEncodeFunction · 0.85

Calls 1

ECCEncryptFunction · 0.85

Tested by 1

TestEncodeFunction · 0.68