Exemple #1
0
func ecReceive(conn net.Conn) {
	var msg = make([]byte, 0)

	priv, err := ecies.ImportPrivatePEM(key)
	if err != nil {
		fmt.Fprintln(os.Stderr, err.Error())
		return
	}

	for {
		var buf = make([]byte, BufSize)
		n, err := conn.Read(buf)
		if err != nil && err == io.EOF {
			break
		} else if err != nil {
			fmt.Fprintln(os.Stderr, err.Error())
			return
		}
		msg = append(msg, buf[:n]...)
	}
	pt, err := echybrid.Decrypt(priv, msg)
	if err != nil {
		fmt.Fprintln(os.Stderr, err.Error())
		return
	}
	os.Stdout.Write(pt)
}
Exemple #2
0
func sendECPubKey(conn net.Conn) bool {
	fmt.Printf("sending public key...")
	key, err := ecies.ImportPrivatePEM(key)
	if err != nil {
		fmt.Fprintln(os.Stderr, err.Error())
		return false
	}
	pubkey, err := ecies.MarshalPublic(&key.PublicKey)
	if err != nil {
		fmt.Fprintln(os.Stderr, err.Error())
		return false
	}
	conn.Write(pubkey)
	fmt.Println("complete")
	return true
}