// Encrypt message with public key of receiver.
// The message can be decrypted only if private key is known.
Encrypt message with public key of receiver.
The message can be decrypted only if private key is known.
// Encrypt message with public key of receiver . // The message can be decrypted only if private key is known .
func (client *Client) Encrypt(receiver crypto.PubKey, msg *Message) *Message {
	var (
		rand = crypto.Rand(gopeer.Get("RAND_SIZE").(uint))
		hash = crypto.SumHash(bytes.Join(
			[][]byte{
				rand,
				client.PubKey().Bytes(),
				receiver.Bytes(),
				[]byte(msg.Head.Title),
				msg.Body.Data,
			},
			[]byte{},
		))
		session = crypto.Rand(gopeer.Get("SKEY_SIZE").(uint))
		cipher  = crypto.NewCipher(session)
	)
	return &Message{
		Head: HeadMessage{
			Diff:    msg.Head.Diff,
			Rand:    cipher.Encrypt(rand),
			Title:   cipher.Encrypt(msg.Head.Title),
			Sender:  cipher.Encrypt(client.PubKey().Bytes()),
			Session: receiver.Encrypt(session),
		},
		Body: BodyMessage{
			Data: cipher.Encrypt(msg.Body.Data),
			Hash: hash,
			Sign: cipher.Encrypt(client.PrivKey().Sign(hash)),
			Npow: crypto.NewPuzzle(msg.Head.Diff).Proof(hash),
		},
	}
}
func ( client * Client ) Encrypt ( receiver crypto . PubKey , msg * Message ) * Message { var ( rand = crypto . Rand ( gopeer . Get ( " " ) . ( uint ) ) hash = crypto . SumHash ( bytes . Join ( [ ] [ ] byte { rand , client . PubKey ( ) . Bytes ( ) , receiver . Bytes ( ) , [ ] byte ( msg . Head . Title ) , msg . Body . Data , } , [ ] byte { } , ) ) session = crypto . Rand ( gopeer . Get ( " " ) . ( uint ) ) cipher = crypto . NewCipher ( session ) ) return & Message { Head : HeadMessage { Diff : msg . Head . Diff , Rand : cipher . Encrypt ( rand ) , Title : cipher . Encrypt ( msg . Head . Title ) , Sender : cipher . Encrypt ( client . PubKey ( ) . Bytes ( ) ) , Session : receiver . Encrypt ( session ) , } , Body : BodyMessage { Data : cipher . Encrypt ( msg . Body . Data ) , Hash : hash , Sign : cipher . Encrypt ( client . PrivKey ( ) . Sign ( hash ) ) , Npow : crypto . NewPuzzle ( msg . Head . Diff ) . Proof ( hash ) , } , } }
Encrypt message with public key of receiver.
Encrypt message with public key of receiver .