Pass data encrypted by URL in ASP.NET MVC

Asked

Viewed 1,052 times

3

I need to pass a link, but I didn’t want to leave it too exposed, I would like to know how to encrypt at least the object id. I created a class for Cryptography, only it generates "/" and this puts as route in MVC.

2 answers

2

Continue using your encryption in the parameters, but to avoid problems with not allowed characters in the Url, before sending the string, use the method Httpcontext.Current.Server.Urlencode().

When reading the string again, use the method Httpcontext.Current.Server.Urldecode().

When you are outside an ASP.NET application, if you are using Framework 4.5 onwards, it is recommended to use the class Webutility to access the methods UrlEncode and UrlDecode.

  • this Httpcontext.Current.Server.Urldecode() can I use in the controller? I’m trying but it’s giving error in Current...

  • Try HttpUtility.UrlEncode, or WebUtility.UrlDecode if you’re on Framwork 4.5.

  • link looked like this: http://localhost:63896/Called/Reopened called/Liuycxqmgeq/F%2buF/Ddasexoxa8kjlos7nrq3qfw93uzjmqaq2kw3iwy%2bZ3Zn2HO, but has not yet opened, gives IIS error, should be pq not putting as Querystring this?

0

Use:

Regex regex1 = new Regex("/");
string result = rgx.Replace('SEU TEXTO CRIPTOGRAFADO', 'QUALQUER SIMBOLO QUE NÃO É USADO E NÃO CAUSA PROBLEMAS';

then add the result to the URL and when to convert use:

Regex regex1 = new Regex('SIMBOLO USADO');
string result = rgx.Replace('SEU TEXTO CRIPTOGRAFADO E CODIFICADO', "/";

Another way would be using POST, which would make your site safer. This encryption doesn’t seem very secure to me, it would be good to search an existing encryption class if you want more security.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.