jeremy
jeremy

Reputation: 1605

how do I? simple scramble/encrypt string in server (ASP.NET) and unscramble/decrypt in javascript

Platform: Server - ASP.NET 3.5 / C#; client side - javascript/jQuery

This is what I want to do

  1. Scramble a string in ASP.NET WebMethod (called through a jQuery Ajax call) before sending to the client
  2. Unscramble it in javascript and display

I'm not looking at any sort of heavy duty encryption AES SHA whatever. I'm only interested in simple obfuscation - so if a user wants to persevere and decrypt the strings (which I will display anyway in a sequence, it's just that I don't want them to see all of them in the mark-up) then they can, it doesn't matter.

Are there any simple schemes to do this?

for clarity:

say I want to send a pre-filled array to the client browser with ["a'"b","c"]

when someone opens the source on the browser, he/she should see, say. ["m","n","o"]

but when I display, I would recompute it to "a" and show it. That's all.

Upvotes: 2

Views: 1818

Answers (3)

eglasius
eglasius

Reputation: 36037

How about transforming it to base64 like the regular asp.net does for the viewstate by default / no encryption, just hiding.

I'd stick to the most basic thing, as youll have the js at the client to get it back anyway. A simple obfuscation algorithmic could be used instead if you need, but I wouldn't bother going into any real encryption for this.

Upvotes: 1

Andreas
Andreas

Reputation: 21881

What ever the intention may be... Why not just implement the simplest "encryption"-algorithm out there

ROT13

Upvotes: 2

KeithS
KeithS

Reputation: 71573

Most algorithms for ciphering/encryption are language-agnostic. If you simply want to obfuscate the string from casual observation, I would implement a simple shift cipher (a->n). You'll have to write the encoder in C#, then the decoder in JavaScript; that's pretty much the whole story. Be aware that if you use the ASCII codes to shift, you have to avoid rolling over into "control" codes like newlines, and you can't include or encode into the ampersand "&" character. It may be simpler to hard-code identical arrays of valid character values, and provide an index offset that is the "shift"..

Upvotes: 1

Related Questions