private static Task <byte[]> GetMessageEnvelopeHash( ICryptographicImplementation cryptographicImplementation, AgentMessageEnvelope envelope) => cryptographicImplementation.Hash( new byte[][] { BitConverter.GetBytes(envelope.Created.Ticks), Encoding.UTF8.GetBytes(envelope.Originator), Encoding.UTF8.GetBytes(envelope.Target), Encoding.UTF8.GetBytes(envelope.MessageType), envelope.Message }.SelectMany(a => a).ToArray());
public static async Task <AgentMessageEnvelope> Create( ICryptographicImplementation cryptographicImplementation, string originator, string target, IAgentMessage message) { var envelope = new AgentMessageEnvelope() { Created = DateTimeOffset.UtcNow, Originator = originator, Target = target, MessageType = message.GetType().Name, Message = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(message)) }; envelope.Signature = await cryptographicImplementation.Sign( await GetMessageEnvelopeHash(cryptographicImplementation, envelope)); return(envelope); }