Esta es una interfaz con la biblioteca mcrypt, la cual soporta
una gran variedad de algoritmos de bloque como DES, TripleDES,
Blowfish (por defecto), 3-WAY, SAFER-SK64, SAFER-SK128, TWOFISH,
TEA, RC2 y GOST en los modos de cifrado CBC, OFB, CFB y
ECB. Adicionalmente, soporta RC6 e IDEA, los cuales se consideran
"no-libres".
Estas funciones trabajan usando mcrypt. Para usar la biblioteca,
descargue libmcrypt-x.x.tar.gz desde http://mcrypt.sourceforge.net/ y siga las instrucciones
de instalación incluidas. Los usuarios de windows
encontrarán todos los binarios compilados de mcrypt que se
necesitan en http://ftp.emini.dk/pub/php/win32/mcrypt/.
A partir de PHP 5.0.0, es necesario usar la versión 2.5.6
o superior de libmcrypt.
You need to compile PHP with the --with-mcrypt[=DIR] parameter to enable this
extension. DIR is the mcrypt install directory. Make sure you compile
libmcrypt with the option
--disable-posix-threads.
Estas constantes están
definidas por esta extensión y estarán disponibles
solamente cuando la extensión ha sido o bien compilada dentro
de PHP o grabada dinámicamente en tiempo de ejecución.
Mcrypt can operate in four block cipher modes (CBC, OFB, CFB, and
ECB). If linked against libmcrypt-2.4.x or higher the functions can also operate
in the block cipher mode nOFB and in STREAM mode. Below you find a list
with all supported encryption modes together with the constants that are
defines for the encryption mode. For a more complete reference and
discussion see Applied Cryptography by Schneier (ISBN 0-471-11709-9).
MCRYPT_MODE_ECB (electronic codebook) is suitable for random data,
such as encrypting other keys. Since data there is short and random,
the disadvantages of ECB have a favorable negative effect.
MCRYPT_MODE_CBC (cipher block chaining) is especially suitable for
encrypting files where the security is increased over ECB
significantly.
MCRYPT_MODE_CFB (cipher feedback) is the best mode for encrypting byte
streams where single bytes must be encrypted.
MCRYPT_MODE_OFB (output feedback, in 8bit) is comparable to CFB, but
can be used in applications where error propagation cannot
be tolerated. It's insecure (because it operates in 8bit
mode) so it is not recommended to use it.
MCRYPT_MODE_NOFB (output feedback, in nbit) is comparable to OFB, but
more secure because it operates on the block size of the algorithm.
MCRYPT_MODE_STREAM is an extra mode to include some stream algorithms
like WAKE or RC4.
Mcrypt puede usarse para cifrar y descifrar usando los cifrados
mencionados anteriormente. Si ha enlazado el software contra
libmcrypt-2.2.x, los cuatro comandos importantes de mcrypt
(mcrypt_cfb(), mcrypt_cbc(),
mcrypt_ecb(), y
mcrypt_ofb()) pueden operar en ambos modos,
los cuales son llamados MCRYPT_ENCRYPT y MCRYPT_DECRYPT,
respectivamente.
Ejemplo 1. Cifrar un valor de entrada con TripleDES bajo 2.2.x en
modo ECB
<?php $llave = "esta es una llave secreta"; $entrada = "Encontrémonos a las 9 en punto en el lugar secreto.";
Atención técnica y comercial: (54)-11-5031-1111 las 24 hs. los 365 días del año. ToWebs, (c) 2008
Virtucom Networks S.A Av. Belgrano 1586, piso 10 (C1093AAQ) Cap. Fed. Bs. As, Argentina.