PHP Doku:: Encryption Filters - filters.encryption.html

Verlauf / Chronik / History: (1) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchAppendicesList of Available FiltersEncryption Filters

Ein Service von Reinhard Neidl - Webprogrammierung.

List of Available Filters

<<Compression Filters

Liste der unterstützten Socket-Transporter>>

Encryption Filters

mcrypt.* and mdecrypt.* provide symmetric encryption and decryption using libmcrypt. Both sets of filters support the same algorithms available to mcrypt extension in the form of mcrypt.ciphername where ciphername is the name of the cipher as it would be passed to mcrypt_module_open(). The following five filter parameters are also available:

mcrypt filter parameters
Parameter Required? Default Sample Values
mode Optional cbc cbc, cfb, ecb, nofb, ofb, stream
algorithms_dir Optional ini_get('mcrypt.algorithms_dir') Location of algorithms modules
modes_dir Optional ini_get('mcrypt.modes_dir') Location of modes modules
iv Required N/A Typically 8, 16, or 32 bytes of binary data. Depends on cipher
key Required N/A Typically 8, 16, or 32 bytes of binary data. Depends on cipher

Beispiel #1 Encrypting file output using 3DES

<?php
$passphrase 
'My secret';

/* Turn a human readable passphrase
 * into a reproducable iv/key pair
 */
$iv substr(md5('iv'.$passphrasetrue), 08);
$key substr(md5('pass1'.$passphrasetrue) . 
               
md5('pass2'.$passphrasetrue), 024);
$opts = array('iv'=>$iv'key'=>$key);

$fp fopen('secret-file.enc''wb');
stream_filter_append($fp'mcrypt.tripledes'STREAM_FILTER_WRITE$opts);
fwrite($fp'Secret secret secret data');
fclose($fp);
?>

Beispiel #2 Reading an encrypted file

<?php
$passphrase 
'My secret';

/* Turn a human readable passphrase
 * into a reproducable iv/key pair
 */
$iv substr(md5('iv'.$passphrasetrue), 08);
$key substr(md5('pass1'.$passphrasetrue) . 
               
md5('pass2'.$passphrasetrue), 024);
$opts = array('iv'=>$iv'key'=>$key);

$fp fopen('secret-file.enc''rb');
stream_filter_append($fp'mdecrypt.tripledes'STREAM_FILTER_READ$opts);
$data rtrim(stream_get_contents($fp));
fclose($fp);

echo 
$data;
?>

Keine BenutzerBeiträge.
- Beiträge aktualisieren...



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)