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?

1
  • The post 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 that the only currently supported overload from that class in that package doesn't have the SerializationMode overload anymore. Commented Dec 26, 2015 at 12:23

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.