/// <summary>
        /// Generates the encrypted log event.
        /// </summary>
        /// <param name="source">The source logging event.</param>
        /// <returns>The source logging event with the message encrypted accordingly</returns>
        public virtual LoggingEvent GenerateEncryptedLogEvent(LoggingEvent source)
        {
            LoggingEvent result;

            try
            {
                var encryptedMessage = MessageEncryption.Encrypt(source.RenderedMessage);

                string exceptionString           = source.GetExceptionString();
                string encryptedExceptionMessage = null;

                if (!string.IsNullOrWhiteSpace(exceptionString))
                {
                    encryptedExceptionMessage = MessageEncryption.Encrypt(exceptionString);
                }

                result = LogEventFactory.CreateEncryptedLoggingEvent(source, encryptedMessage, encryptedExceptionMessage);
            }
            catch (Exception ex)
            {
                // Ensure that the logging encryption never fails with an unexpected exception, rather, create an error
                // log event so that can be logged instead. This is to ensure that we aren't inadvertently leaking
                // sensitive data in our logs if an error occurs, better to log nothing than leak data!
                result = LogEventFactory.CreateErrorEvent(ex.Message);
            }

            return(result);
        }
Example #2
0
        protected EncryptedMessage encryptMessage(string message, Guid remoteId)
        {
            // encrypt message
            var em = MessageEncryption.Encrypt(Encoding.UTF8.GetBytes(message));

            // encrypt key
            encryptKey(ref em, remoteId);

            return(em);
        }