简体   繁体   中英

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.

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

ROT13

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"..

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM