public static string Format(this IPassiveMessage message, HubContext context) { using (var stream = new MemoryStream()) { message.SerializeTo(stream, context); stream.Position = 0; using (var reader = new StreamReader(stream)) { return(reader.ReadToEnd()); } } }
public IPassiveMessage EncryptMessage(IPassiveMessage message, CryptographyContext context) { using (var stream = new MemoryStream()) { message.SerializeTo(stream, context.HubContext); stream.Position = 0; using (var reader = new StreamReader(stream)) { var originalMessage = reader.ReadToEnd(); var encryptedMessage = EncryptMessage(originalMessage, context); var signature = GenarateSinature(originalMessage, context); return(new EncryptedPassiveMessage { MsgSignature = signature, TimeStamp = context.MsgTimestamp, Nonce = context.MsgNonce, Encrypt = encryptedMessage }); } } }