开发者

Scrambling/Unscrambling a string in Classic ASP

I'm wanting to send a string that has some meaning through the URL.

I know that I could probably do other things to send a string, but this is the only way in this situation.

I'm wanting send it and an unreadable format and be able to get the original string back later. I'm t开发者_开发问答rying to avoid the words encrypt/decrypt because I've done research and It seems a bit more envolved than what I'm wanting in classic ASP( unless I'm missing something ). So I'm not really wanting to IMPLEMENT a encrypt/decrypt algorithm. I'm hoping there is something built into ASP that will allow me to do this.

I'm looking for both the way to scramble the message and a way to get it back.

Any suggestions?


No, there's not a default built in implementation for encrypting/decrypting a string in classic ASP. That's why there are a million custom examples on how to encrypt/decrypt strings in classic ASP. It's really not as "involved" as you would think. For example, check out this example from 2002:

Encrypting/Decrypting Classic ASP querystrings


If you're looking to scramble the string (as opposed to encrypting it) then write your own rot13 encoder/decoder.

The same algorithm can easily be applied to translate all ASCII characters.

You'd probably be better off storing the same data in the session though.


Why not send the information in a POST instead of a GET? That way it's not visible to the user. You would need to include more detail though for us to know if that is a viable options.

-- OR --

How about this genius code....

<%

 'Functions for Encrypting/Decrypting querystrings

  '******************************'******************************

Function Encrypt(Input)

Dim Temp

Temp = CDbl(Input)
Temp = Temp * 7
Temp = Temp + 37
Temp = Temp * 13
Temp = Temp + 91

Encrypt = Temp 

End Function 'Encrypt

'******************************

Function Decrypt(Input)

Dim Temp

Temp = CDbl(Input)
Temp = Temp - 91
Temp = Temp / 13
Temp = Temp - 37
Temp = Temp / 7

Decrypt = Temp 

End Function 'Decrypt

'******************************

%>

Bonus... Now you get to write your Sql Queries like this to find a record when the query string is encrypted...

Select * from sometable where id = (((@id * 7) + 37) *13) + 91

Please don't use this...


Doug Chamberlain should mentioned that his example for numerical values only.

And if you want to really encrypt what you are passing between ASP pages use link which was suggested by George.

Tested by me and it does exactly what you need, no matter what type of data you are passing: strings or numerical.

And if you going to re-use any of data then session variable is best bet for you, you do not need to scramble data for that. Keep in mind that from testing your site should be using port 80 for session variable work as intended.

There is some kind of bug in IIS 7 which clearing up sessions in really short period of time or if your user submit anything else.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜