0

I render an ActionLink like this:

@Html.ActionLink(techName, "Details","Home", new { TopicID = item.TechID },null)

I would like to encrypt the query string, something like this: Home/Details?TopicID=Ek7vP1YwVhc=

I searched on this topic and found a piece of code to encrypt and decrypt the data:

(new MvcSerializer()).Serialize(<Your data here>, SerializationMode.EncryptedAndSigned)

And then to reverse the process...

(new MvcSerializer()).Deserialize(<Serialized data here>, SerializationMode.EncryptedAndSigned)

How to use the above approach to encrypt and decrypt my query string?

Community
  • 1
  • 1
Thomas
  • 33,544
  • 126
  • 357
  • 626
  • The [post](http://stackoverflow.com/a/24165460/266143) you copied that code from mentions the "MVC Futures" package, and there is another answer in that question that does show a working approach. Why are you asking for help about getting the lowest-voted answer in that question to work? What have you tried? If you search a bit further, you'll [find](http://stackoverflow.com/questions/25828553/cannot-find-html-serialize-helper-in-mvc-5-futures) that the only currently supported overload from that class in that package doesn't have the `SerializationMode` overload anymore. – CodeCaster Dec 26 '15 at 12:23

1 Answers1

1

You say you wish to encrypt (prevent eavesdroppers from being able to look at secret data), but it sounds more like you want to encode - to format data such that it can safely be used as a URI component.

The example you show looks like base64:

var base64EncodedText = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(myText));

Another approach is Uri.EscapeString:

var uriEncodedText = Uri.EscapeString(myText);

The latter only changes special characters and thus may look more human-readable. This can be an advantage or a disadvantage.

Timo
  • 7,992
  • 4
  • 49
  • 67