Encode eciesPublicKey
(eciesPublicKey string, msg []byte)
| 40 | |
| 41 | // Encode eciesPublicKey |
| 42 | func 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 | } |
| 53 | func ECCEncrypt(pt []byte, puk ecies.PublicKey) ([]byte, error) { |
| 54 | ct, err := ecies.Encrypt(rand.Reader, &puk, pt, nil, nil) |
| 55 | return ct, err |