PDA

View Full Version : Encryption



kkroo
05-27-2006, 03:17 PM
Hey,

Is there any type of encryption that is both in javascript and in php?

What i want to do is be able to encrypt something with a php script and decrypt it in javascript so that it is not readable to the human eye.


Thanks in advance

shachi
05-27-2006, 06:10 PM
Are you talking about something like this: http://scriptasylum.com/tutorials/encdec/encode-decode.html
??:confused:

Twey
05-27-2006, 06:16 PM
No, s/he isn't. I think s/he is talking about actual encryption.
kkroo: Unfortunately, this is not possible. The reason for this is that your Javascript is visible to anyone, and you must include the decryption algorithm and any necessary keys in that Javascript. Ergo, it is impossible to do this securely.

shachi
05-27-2006, 06:28 PM
OOPS!! Sorry for the misunderstanding. :D
Yea that seems to be a disadvantage of making rich internet APIs in a client side scripting language.:(

kkroo
05-27-2006, 06:31 PM
The method shachi has is alright, you cant read the source code with it. But what php function would be able to do that?

shachi
05-27-2006, 06:33 PM
the PHP(simple one)

echo '<script type="text/javascript">document.write(unescape(encoded code));</script>

kkroo
05-27-2006, 06:41 PM
I mean doing it without javascript, like an actual php function

shachi
05-27-2006, 06:44 PM
Umm.. sorry to disappoint you but I don't think that it is possible or may be my knowledge is not enough as I am not that good at PHP. Try asking the guyz on IRC freenode. I bet they would help you out of this problem. But that's just an advice.

Good luck!!!:)

shachi
05-27-2006, 06:45 PM
or may be Twey knows something about it?? Try messaging him or wait till he looks at this message again.

Twey
05-27-2006, 08:11 PM
<?php
function urlfuscate($str) {
$op = "";
for($i=0;$i<strlen($str);$i++)
$op .= "%" . bin2hex(substr($str, $i, 1));
return $op;
}
?>

kkroo
05-28-2006, 09:07 AM
Thanks a lot!!!

joycie
09-01-2006, 03:53 AM
<?php
function urlfuscate($str) {
$op = "";
for($i=0;$i<strlen($str);$i++)
$op .= "%" . bin2hex(substr($str, $i, 1));
return $op;
}
?>

Sorry if my question sounds silly-
Is this code valid also for php file that comes with html and javascript code?
If so how to apply the code to do encryption?

Many thanks in advance.

codeexploiter
09-01-2006, 04:04 AM
Yes it is valid for a php file that might contain HTML Tags and Javascript client-side scripts.

PHP executes in the server after the results, html & client-side scripts will be delivered to the client's browser.

Twey
09-01-2006, 02:53 PM
I do not recommend this function for source code obfuscation or the like except for extremely trivial purposes. It is not secure, and since it requires Javascript to undo on the client (except in URLs), it should not be used for anything critical to the functionality of your site.