473,387 Members | 1,548 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

PHP querystring encryption,

Hi,

I've had to quickly servers and need to turn an ASP script into PHP, i
got the original script from: -

http://www.4guysfromrolla.com/webtech/012000-1.shtml

Does anyone know of a PHP version of this? otherwise it's gonna be a
few hours sifting through it and converting it line by line.

Any suggestions very much welcome.

Jul 17 '05 #1
6 6125
JDS
On Mon, 20 Jun 2005 11:06:15 -0700, Ian N wrote:
Does anyone know of a PHP version of this? otherwise it's gonna be a
few hours sifting through it and converting it line by line.


No, but you can probably do something similar using a combination of
serialize() + urlencode() and decoding it with urldecode()

If you *really* want to obfuscate the query string, try throwing
base64_encode() (and base64_decode()) into the mix.

Note that this is not really encryption, merely obfuscation, and the ASP
example is also not really encryption, merely obfuscation.

--
JDS | je*****@example.invalid
| http://www.newtnotes.com
DJMBS | http://newtnotes.com/doctor-jeff-master-brainsurgeon/

Jul 17 '05 #2
JDS
On Mon, 20 Jun 2005 14:13:50 -0400, JDS wrote:
Note that this is not really encryption, merely obfuscation, and the ASP
example is also not really encryption, merely obfuscation.


Ooops, my blow, hank. It really *is* encryption. I just read the article
in more detail.

Look at PHP's mcrpypt* functions.

http://us4.php.net/manual/en/functio...odule-open.php

later...

--
JDS | je*****@example.invalid
| http://www.newtnotes.com
DJMBS | http://newtnotes.com/doctor-jeff-master-brainsurgeon/

Jul 17 '05 #3
Thanks for the reply, i'm looking into the php version now.

My main problem is that it's got to be passed from a PHP server to an
ASP server, so the encryption must be spot on or it won't decrypt.

In theory it should work fine, i'm not so convinced it'll be so simple
in practice sadly.

Jul 17 '05 #4
NC
Ian N wrote:

I've had to quickly servers and need to turn an ASP script
into PHP, i got the original script from: -

http://www.4guysfromrolla.com/webtech/012000-1.shtml

Does anyone know of a PHP version of this? otherwise it's gonna be a
few hours sifting through it and converting it line by line.


Hours? How about ten minutes? The script given at

http://www.4guysfromrolla.com/webtech/110599-1.2.shtml

translates as follows:

$g_CryptThis = "Now is the time for all good men to come to the aid of
their country.";
$g_KeyLocation = "key.txt";

$g_Key = substr(ReadKeyFromFile($g_KeyLocation), 0,
strlen($g_CryptThis));

echo "<p>ORIGINAL STRING: ", $g_CryptThis, "<p>";
echo "<p>KEY VALUE: ", $g_Key, "<p>";
echo "<p>ENCRYPTED CYPHERTEXT: ", EnCrypt($g_CryptThis), "<p>";
echo "<p>DECRYPTED CYPHERTEXT: ", DeCrypt(EnCrypt($g_CryptThis)),
"<p>";

function EnCrypt($strCryptThis) {
global $g_Key;
for ($i = 0; $i < strlen($strCryptThis); $i++) {
$iKeyChar = ord($g_Key{$i});
$iStringChar = ord($strCryptThis{$i});
// *** uncomment below to encrypt with addition,
// $iCryptChar = $iStringChar + $iKeyChar;
$iCryptChar = $iKeyChar ^ $iStringChar;
$strEncrypted = $strEncrypted . chr($iCryptChar);
}
return $strEncrypted;
}

function DeCrypt($strEncrypted) {
global $g_Key;
for ($i = 0; $i < strlen($strEncrypted); $i++) {
$iKeyChar = ord($g_Key{$i});
$iStringChar = ord($strEncrypted{$i});
// *** uncomment below to decrypt with subtraction
// $iDeCryptChar = $iStringChar - $iKeyChar;
$iDeCryptChar = $iKeyChar ^ $iStringChar;
$strDecrypted = $strDecrypted . chr($iDeCryptChar);
}
return $strDecrypted;
}

function ReadKeyFromFile($strFileName) {
$key = file_get_contents($strFileName);
$key = str_replace("\r", '', $key);
$key = str_replace("\n", '', $key);
return $key;
}

Cheers,
NC

Jul 17 '05 #5
NC
Ian N wrote:

My main problem is that it's got to be passed from a PHP
server to an ASP server,
Be sure to safeguard the key in both places...
the encryption must be spot on or it won't decrypt.
It is.
In theory it should work fine, i'm not so convinced it'll
be so simple in practice sadly.


Well, you should try it... :)

Cheers,
NC

Jul 17 '05 #6
JDS
On Wed, 22 Jun 2005 13:04:40 -0700, NC wrote:
Be sure to safeguard the key in both places...


Maybe, try encrypting the key with another key? And then, for extra
security, encrypt that key with another key. That oughtta do it.

--
JDS | je*****@example.invalid
| http://www.newtnotes.com
DJMBS | http://newtnotes.com/doctor-jeff-master-brainsurgeon/

Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Arjen | last post by:
Hello, Can somebody tell my if it is posible to create a QueryString encryption/decryption that works from a higher level then the code view... For example: I have an URL like...
4
by: Jason Shohet | last post by:
I'm getting a URL w/ a querystring coming in to start my app. In session_start, I was thinking of scrambling that querystring to keep it from prying eyes.... Any ideas? Doesn't need to be...
1
by: Nils N | last post by:
Hi all, Does anyone have a best practice for performring querystring authentication. I am now sending an email with a url to which the user clicks to confirm his or her registration. The url...
2
by: Craig HB | last post by:
I need to pass a variable in a querystring that I want to hide from the user. eg www.abc.com?UserID=555 and the UserID must be hidden. I was thinking of encrypting the ID, using a UserGUID that...
2
by: Ryan | last post by:
Hi. I am trying to encrypt some data being passed between two aspx pages using querystring. I have tried bith DES and Rijndael and have run across the following problem. After either provider...
2
by: Ram | last post by:
Hi, I am passing values from one form to another using querystring. It is easy for anyone to tamper these values. Now i don't want to show any values in the url .How can be this done?. I don't...
4
by: Islamegy® | last post by:
I give up.. I tried everything to encrypt querystring and decrypt it back but this never success.. i use RSA encryption. I always get excption when Convert fromBase64String so i tried...
2
by: gandhibasnet | last post by:
Using : System.Web.HttpUtility.UrlEncode() I have used the following code : Response.Redirect("Receive_encrypted_data.aspx?valz="+System.Web.HttpUtility.UrlEncode(TextBox1.Text)); but the...
3
by: pingsheng | last post by:
Dear all, I have a form with dynamically created input fields. These fields go to next page for submitting into SQL database. The thing is all fields are the same but 4 fields. So each record...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.