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.
c# asp.net-mvc encryption
add a comment |
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.
c# asp.net-mvc encryption
add a comment |
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.
c# asp.net-mvc encryption
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
c# asp.net-mvc encryption
asked Nov 12 at 19:59
S.Purtan
34
34
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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