O'Reilly logo

PHP 5 Kochbuch, Third Edition by Stephan Schmidt, Ulrich Speidel, Matthias Brusdeylins, Carsten Lucke, Adam Trachtenberg, David Sklar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

17.7 Daten ver- und entschlüsseln

Problem

Sie wollen mit einem von mehreren gebräuchlichen Algorithmen Daten ver- und entschlüsseln.

Lösung

Benutzen Sie die PHP-Erweiterung mcrypt:

$schluessel  = 'That golden key that opes the palace of eternity.';
$daten = 'The chicken escapes at dawn. Send help with Mr. Blue.';
$alg  = MCRYPT_BLOWFISH;
$modus = MCRYPT_MODE_CBC;

$iv = mcrypt_create_iv(mcrypt_get_iv_size($alg,$modus),MCRYPT_DEV_URANDOM);
$verschluesselte_daten = mcrypt_encrypt($alg, $schluessel, $daten, $modus, $iv);
$zeichentext = base64_encode($verschluesselte_daten);

print $zeichentext."\n";
$decodiert = mcrypt_decrypt($alg,$key,base64_decode($zeichentext),$modus,$iv);
print $decodiert."\n";
NNB9WnuCYjyd3Y7vUh7XDfWFCWnQY0BsMehHNmBHbGOdJ3cM+yghABb/XyrJ+w3xz9tms74/a70= ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required