I’m developing a Web Site using ASP.NET MVC 3, Nowadays I need to encrypt the ID of my customer’s URL. For example:
http://mysite.com/person?id=42
to something like that:
http://mysite.com/person?id=Dfjhasdfh33kASDG868365çkhg54sdSDFD
It need be secure.
When I say secure, It means hard to any one discover the correct ID
Is there any library to do that?
Many secure web payments one of then like paypal uses this type of approach:
https://paypal.com/br/webscr?info=CNS9tFsVM_tv4c18gHgZ3OMH2zblN7GWDQoyamVF3mzNh7vGDuhiKU3
If you REALLY want to encrypt the query param, it’s very simple, just use any encryptor provided by .Net and then use an attribute or a httpmodule to decrypt the param.
The most important thing is to ALWAYS validate the request. If you can do it a POST with anti forgery token, do it. Then, always check the user credentials if that user has access to the protected resource.
It’s not hard at all, but you have to take it slowly and handle every scenario you can think of. Use a white list approach: only those who meet some conditions are allowed.