Ich habe versucht ein text mit JavaScript TripleDES zu verschlüsseln und PHP TripleDES zu entschlüsseln, was jedoch fehl schlug!
Nun meine Frage: Ist das überhaupt möglich?
Ich habe Scripte im Netz gefunden um eine TripleDES Verschlüsselung per PHP und JavaScript auszuführen! Beide tun auc ihren Dienst, aber beide kommen zu einem anderen Ergebnis!
Index.php:
PHP-Code:
<?php
require("des.inc.php");
require("password.inc.php");
$key = "hier steht mein passwort";
$rand_password = rand_password();
$key_new = $key;
?>
<html>
<head>
<title>Zufallspasswort</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" src="md5.inc.js">
</script>
<script language="JavaScript" src="des.inc.js">
</script>
<script language="JavaScript" src="base64.inc.js">
</script>
<style>
span
{
font-weight:bold;
}
</style>
</head>
<body>
<script language="JavaScript">
key = '<?php echo $key; ?>'; //String(document.get_userpw.password.value);
rand = '<?php echo $rand_password; ?>';
document.write("<br>n<br>n<span>JavaScript:</span>n<br>n<span>Passwort:</span> " + key + "n<br>n" + "<span>Zufall:</span> " + rand + "n<br>n");
key = MD5(key);
document.write("<span>MD5 - Hash:</span> " + key + "n<br>n");
document.write("<span>3 DES - Hash:</span> " + TripleDES(key, rand, 1, 0) + "n<br>n");
key = TripleDES(key, rand, 1, 0);
document.write("<span>3 DES - Hash:</span> " + key + "n<br>n");
key = Base64Encode(key);
document.write("<span>Base64 - Code:</span> " + key + "n<br>n<br>n");
</script>
<?php
echo "<span>PHP:</span>n<br>n<span>Passwort:</span> ".$key."n<br>n<span>Zufall:</span> ".$rand_password."n<br>n";
$key = md5($key);
echo "<span>MD5 - Hash:</span> ".$key."n<br>n";
$key = tripledes($key, $rand_password);
echo "<span>3 DES - Hash:</span> ".$key."n<br>n";
echo "<span>Base64 - Code:</span> ".base64_encode($key);
?>
<br>
<br>
</body>
</html>
password.inc.php:
PHP-Code:
<?php
function rand_password()
{
$zahl = "";
$password = "";
mt_srand((double)microtime()*1000000);
$laenge = mt_rand(24,48);
for($i=0; $i < $laenge; $i++)
{
$num = mt_rand(48,122);
if ($num >= 57 && $num <= 65 || $num >= 90 && $num <= 97)
{
$i--;
continue;
}
$password .= chr($num);
}
return $password;
}
function get_password($user)
{
$file = "add_files/safe/.htpasswd";
$fd = fopen ($file, "r");
$users = 0;
do
{
$user_data[$users] = fgetcsv ($fd, 100, ":");
if ($user_data[$users][0] == $user)
{
if (fclose($fd))
$close = true;
return $user_data[$users][1];
break;
}
$users++;
} while (!feof($fd));
if (!$close)
fclose($fd);
return $user_data;
}
function make_keys($rand_password)
{
$user_data = get_password("all");
$users = count($user_data)-1;
for ($user = 0; $user <= $users; $user++)
{
$file = "add_files/safe/".$user_data[$user][0].".safe";
$fd = fopen ($file, "w+");
fwrite ($fd, base64_encode(tripledes($user_data[$user][1], $rand_password)));
fclose ($fd);
}
}
?>
des.inc.php gibts auf anfrage
Meine Ausgabe:
Siehe hier für ausgabe