Encryption using crypto in MVC Asp.net on Id only











up vote
0
down vote

favorite












I have followed an example online for this, however it seems that a lot of these articles do not give you everything you need. I am not sure why people post articles that are partial. Custom written code you will almost never find an answer for what the intended was supposed to be. As a beginner it makes it hard to learn and understand. It was not on this site either by the way. So I have 4 classes Crypto, CryptoValueProvider, CryptoValueProviderAttributes, and CryptoValueProviderFactory. And have registered the proper code in Global.asax. The blank area is in the Crypto class. What I would like to do is change www.somewebsite.com/users/edit/5 to be www.somewebsite.com/users/edit/ndvnq;owirwghbqasldkhgf. When a company admin changes or edits there information I would like it to be encrypted as so they cannot just change 5 to 10 and see someone else's info. This solution looks very good as far as not having to place a lot of code in several pages.
Below is the code I have:



Usage:



[CryptoValueProvider] // This is apparently all you have to do for this to work
public ActionResult UserEdit(int id)
{
return View();
}


Crypto Class - Where my issue is - Need examples of what should go here



    public static class Crypto
{
public static string Encrypt(Dictionary<string, string> keyValue)
{
// encrypt query string key value pair

}

public static Dictionary<string, string> Decrypt(string encryptedText)
{
// decrypt encrypted query string into key value pair
}
}


CryptoValueProvider:



    public class CryptoValueProvider : IValueProvider
{
RouteData routeData = null;
Dictionary<string, string> dictionary = null;

public CryptoValueProvider(RouteData routeData)
{
this.routeData = routeData;
}

public bool ContainsPrefix(string prefix)
{
if (this.routeData.Values["id"] == null)
{
return false;
}

this.dictionary = Crypto.Decrypt(this.routeData.Values["id"].ToString());

return this.dictionary.ContainsKey(prefix.ToUpper());
}

public ValueProviderResult GetValue(string key)
{
ValueProviderResult result;
result = new ValueProviderResult(this.dictionary[key.ToUpper()],
this.dictionary[key.ToUpper()], CultureInfo.CurrentCulture);
return result;
}
}


CryptoValueProviderAttributes:



    public class CryptoValueProviderAttribute : FilterAttribute, IAuthorizationFilter
{
public void OnAuthorization(AuthorizationContext filterContext)
{
filterContext.Controller.ValueProvider = new CryptoValueProvider(filterContext.RouteData);
}
}


CryptoValueProviderFactory:



    public class CryptoValueProviderFactory : ValueProviderFactory
{
public override IValueProvider GetValueProvider(ControllerContext controllerContext)
{
return new CryptoValueProvider();
}
}


Global.asax:



    protected void Application_Start()
{
ValueProviderFactories.Factories.Insert(0, new CryptoValueProviderFactory());
}


Thank you for your help... It is much appreciated.










share|improve this question


























    up vote
    0
    down vote

    favorite












    I have followed an example online for this, however it seems that a lot of these articles do not give you everything you need. I am not sure why people post articles that are partial. Custom written code you will almost never find an answer for what the intended was supposed to be. As a beginner it makes it hard to learn and understand. It was not on this site either by the way. So I have 4 classes Crypto, CryptoValueProvider, CryptoValueProviderAttributes, and CryptoValueProviderFactory. And have registered the proper code in Global.asax. The blank area is in the Crypto class. What I would like to do is change www.somewebsite.com/users/edit/5 to be www.somewebsite.com/users/edit/ndvnq;owirwghbqasldkhgf. When a company admin changes or edits there information I would like it to be encrypted as so they cannot just change 5 to 10 and see someone else's info. This solution looks very good as far as not having to place a lot of code in several pages.
    Below is the code I have:



    Usage:



    [CryptoValueProvider] // This is apparently all you have to do for this to work
    public ActionResult UserEdit(int id)
    {
    return View();
    }


    Crypto Class - Where my issue is - Need examples of what should go here



        public static class Crypto
    {
    public static string Encrypt(Dictionary<string, string> keyValue)
    {
    // encrypt query string key value pair

    }

    public static Dictionary<string, string> Decrypt(string encryptedText)
    {
    // decrypt encrypted query string into key value pair
    }
    }


    CryptoValueProvider:



        public class CryptoValueProvider : IValueProvider
    {
    RouteData routeData = null;
    Dictionary<string, string> dictionary = null;

    public CryptoValueProvider(RouteData routeData)
    {
    this.routeData = routeData;
    }

    public bool ContainsPrefix(string prefix)
    {
    if (this.routeData.Values["id"] == null)
    {
    return false;
    }

    this.dictionary = Crypto.Decrypt(this.routeData.Values["id"].ToString());

    return this.dictionary.ContainsKey(prefix.ToUpper());
    }

    public ValueProviderResult GetValue(string key)
    {
    ValueProviderResult result;
    result = new ValueProviderResult(this.dictionary[key.ToUpper()],
    this.dictionary[key.ToUpper()], CultureInfo.CurrentCulture);
    return result;
    }
    }


    CryptoValueProviderAttributes:



        public class CryptoValueProviderAttribute : FilterAttribute, IAuthorizationFilter
    {
    public void OnAuthorization(AuthorizationContext filterContext)
    {
    filterContext.Controller.ValueProvider = new CryptoValueProvider(filterContext.RouteData);
    }
    }


    CryptoValueProviderFactory:



        public class CryptoValueProviderFactory : ValueProviderFactory
    {
    public override IValueProvider GetValueProvider(ControllerContext controllerContext)
    {
    return new CryptoValueProvider();
    }
    }


    Global.asax:



        protected void Application_Start()
    {
    ValueProviderFactories.Factories.Insert(0, new CryptoValueProviderFactory());
    }


    Thank you for your help... It is much appreciated.










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have followed an example online for this, however it seems that a lot of these articles do not give you everything you need. I am not sure why people post articles that are partial. Custom written code you will almost never find an answer for what the intended was supposed to be. As a beginner it makes it hard to learn and understand. It was not on this site either by the way. So I have 4 classes Crypto, CryptoValueProvider, CryptoValueProviderAttributes, and CryptoValueProviderFactory. And have registered the proper code in Global.asax. The blank area is in the Crypto class. What I would like to do is change www.somewebsite.com/users/edit/5 to be www.somewebsite.com/users/edit/ndvnq;owirwghbqasldkhgf. When a company admin changes or edits there information I would like it to be encrypted as so they cannot just change 5 to 10 and see someone else's info. This solution looks very good as far as not having to place a lot of code in several pages.
      Below is the code I have:



      Usage:



      [CryptoValueProvider] // This is apparently all you have to do for this to work
      public ActionResult UserEdit(int id)
      {
      return View();
      }


      Crypto Class - Where my issue is - Need examples of what should go here



          public static class Crypto
      {
      public static string Encrypt(Dictionary<string, string> keyValue)
      {
      // encrypt query string key value pair

      }

      public static Dictionary<string, string> Decrypt(string encryptedText)
      {
      // decrypt encrypted query string into key value pair
      }
      }


      CryptoValueProvider:



          public class CryptoValueProvider : IValueProvider
      {
      RouteData routeData = null;
      Dictionary<string, string> dictionary = null;

      public CryptoValueProvider(RouteData routeData)
      {
      this.routeData = routeData;
      }

      public bool ContainsPrefix(string prefix)
      {
      if (this.routeData.Values["id"] == null)
      {
      return false;
      }

      this.dictionary = Crypto.Decrypt(this.routeData.Values["id"].ToString());

      return this.dictionary.ContainsKey(prefix.ToUpper());
      }

      public ValueProviderResult GetValue(string key)
      {
      ValueProviderResult result;
      result = new ValueProviderResult(this.dictionary[key.ToUpper()],
      this.dictionary[key.ToUpper()], CultureInfo.CurrentCulture);
      return result;
      }
      }


      CryptoValueProviderAttributes:



          public class CryptoValueProviderAttribute : FilterAttribute, IAuthorizationFilter
      {
      public void OnAuthorization(AuthorizationContext filterContext)
      {
      filterContext.Controller.ValueProvider = new CryptoValueProvider(filterContext.RouteData);
      }
      }


      CryptoValueProviderFactory:



          public class CryptoValueProviderFactory : ValueProviderFactory
      {
      public override IValueProvider GetValueProvider(ControllerContext controllerContext)
      {
      return new CryptoValueProvider();
      }
      }


      Global.asax:



          protected void Application_Start()
      {
      ValueProviderFactories.Factories.Insert(0, new CryptoValueProviderFactory());
      }


      Thank you for your help... It is much appreciated.










      share|improve this question













      I have followed an example online for this, however it seems that a lot of these articles do not give you everything you need. I am not sure why people post articles that are partial. Custom written code you will almost never find an answer for what the intended was supposed to be. As a beginner it makes it hard to learn and understand. It was not on this site either by the way. So I have 4 classes Crypto, CryptoValueProvider, CryptoValueProviderAttributes, and CryptoValueProviderFactory. And have registered the proper code in Global.asax. The blank area is in the Crypto class. What I would like to do is change www.somewebsite.com/users/edit/5 to be www.somewebsite.com/users/edit/ndvnq;owirwghbqasldkhgf. When a company admin changes or edits there information I would like it to be encrypted as so they cannot just change 5 to 10 and see someone else's info. This solution looks very good as far as not having to place a lot of code in several pages.
      Below is the code I have:



      Usage:



      [CryptoValueProvider] // This is apparently all you have to do for this to work
      public ActionResult UserEdit(int id)
      {
      return View();
      }


      Crypto Class - Where my issue is - Need examples of what should go here



          public static class Crypto
      {
      public static string Encrypt(Dictionary<string, string> keyValue)
      {
      // encrypt query string key value pair

      }

      public static Dictionary<string, string> Decrypt(string encryptedText)
      {
      // decrypt encrypted query string into key value pair
      }
      }


      CryptoValueProvider:



          public class CryptoValueProvider : IValueProvider
      {
      RouteData routeData = null;
      Dictionary<string, string> dictionary = null;

      public CryptoValueProvider(RouteData routeData)
      {
      this.routeData = routeData;
      }

      public bool ContainsPrefix(string prefix)
      {
      if (this.routeData.Values["id"] == null)
      {
      return false;
      }

      this.dictionary = Crypto.Decrypt(this.routeData.Values["id"].ToString());

      return this.dictionary.ContainsKey(prefix.ToUpper());
      }

      public ValueProviderResult GetValue(string key)
      {
      ValueProviderResult result;
      result = new ValueProviderResult(this.dictionary[key.ToUpper()],
      this.dictionary[key.ToUpper()], CultureInfo.CurrentCulture);
      return result;
      }
      }


      CryptoValueProviderAttributes:



          public class CryptoValueProviderAttribute : FilterAttribute, IAuthorizationFilter
      {
      public void OnAuthorization(AuthorizationContext filterContext)
      {
      filterContext.Controller.ValueProvider = new CryptoValueProvider(filterContext.RouteData);
      }
      }


      CryptoValueProviderFactory:



          public class CryptoValueProviderFactory : ValueProviderFactory
      {
      public override IValueProvider GetValueProvider(ControllerContext controllerContext)
      {
      return new CryptoValueProvider();
      }
      }


      Global.asax:



          protected void Application_Start()
      {
      ValueProviderFactories.Factories.Insert(0, new CryptoValueProviderFactory());
      }


      Thank you for your help... It is much appreciated.







      c# asp.net-mvc encryption






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 12 at 19:59









      S.Purtan

      34




      34





























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53269256%2fencryption-using-crypto-in-mvc-asp-net-on-id-only%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53269256%2fencryption-using-crypto-in-mvc-asp-net-on-id-only%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

          ComboBox Display Member on multiple fields

          Is it possible to collect Nectar points via Trainline?