Ejemplo n.º 1
0
        public async Task <string> EncryptEntity <TEntity>(TEntity entidad, bool useHashing = true) where TEntity : class
        {
            if (entidad == null)
            {
                throw new ArgumentNullException("Entidad a encriptar no puede estar nula!.");
            }

            string jsonEntity = await Task.Run(() => JsonConvert.SerializeObject(entidad, JsonSerializerOptionsConfiguration.ReturnJsonSerializerSettings()));

            return(EncryptJson(jsonEntity, useHashing));
        }
Ejemplo n.º 2
0
        public static void Register(HttpConfiguration config)
        {
            // Se registra el handler que encripta y desencripta los requests y response, de manera global si lo pones aca
            //GlobalConfiguration.Configuration.MessageHandlers.Add(new EncryptedServerHandler(new SecureMessagesHelper()));
            GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings = JsonSerializerOptionsConfiguration.ReturnJsonSerializerSettings();

            // Web API routes
            config.MapHttpAttributeRoutes();
            config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;

            var cors = new EnableCorsAttribute(@"*", "*", "*");

            config.EnableCors(cors);

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.Optional },
                constraints: null,
                handler: new EncryptedServerHandler(new SecureMessagesHelper(), new HttpControllerDispatcher(GlobalConfiguration.Configuration)) // De manera por route si lo pones aca
                );
        }