Beispiel #1
0
        public static Payload MakePayload(PayloadType type, string replyToId, byte[] data, string messageId)
        {
            var payload = new Payload {
                Type = type, Data = data
            };

            if (!string.IsNullOrWhiteSpace(replyToId))
            {
                payload.ReplyToId = replyToId.FromHexString();
            }
            else if (!string.IsNullOrWhiteSpace(messageId))
            {
                payload.MessageId = messageId.FromHexString();
            }
            else
            {
                payload.MessageId = PseudoRandom.RandomBytes(Constants.MessageIdLength);
            }

            return(payload);
        }
Beispiel #2
0
        private IList <MessagePayload> EncryptPayloadMany(byte[] payload, IList <string> destinations)
        {
            var nonce = PseudoRandom.RandomBytes(Hash.NonceLength);
            var key   = PseudoRandom.RandomBytes(Hash.KeyLength);

            var encryptedPayload = Hash.EncryptSymmetric(payload, nonce, key);

            var result = new List <MessagePayload>();

            for (int i = 0; i < destinations.Count; i++)
            {
                var publicKey    = Common.Address.AddressToPublicKey(destinations[i]);
                var encryptedKey = this.Key.Encrypt(key, publicKey);

                var mergedNonce = encryptedKey.Nonce.Concat(nonce).ToArray();

                var message = MessageFactory.MakeMessage(encryptedPayload, true, mergedNonce, encryptedKey.Message);

                result.Add(message);
            }

            return(result);
        }