Tuesday, May 15, 2012
Encrypting and decrypting in PHP
Table below lists all the possible mcrypt algorithms, including the constant value used to indicate the algorithm, the key and block sizes in bits, and whether the algorithm is supported libmcrypt 2.2.x and 2.4.x.
Algorithm constant | Description | Key size | Block size | 2.2.x | 2.4.x |
---|---|---|---|---|---|
MCRYPT_3DES | Triple DES | 168 (112 effective) | 64 | Yes | Yes |
MCRYPT_TRIPLEDES | Triple DES | 168 (112 effective) | 64 | No | Yes |
MCRYPT_3WAY | 3way (Joan Daemen) | 96 | 96 | Yes | No |
MCRYPT_THREEWAY | 3way | 96 | 96 | Yes | Yes |
MCRYPT_BLOWFISH | Blowfish (Bruce Schneier) | Up to 448 | 64 | No | Yes |
MCRYPT_BLOWFISH_COMPAT | Blowfish with compatibility to other implementations | Up to 448 | 64 | No | Yes |
MCRYPT_BLOWFISH_128 | Blowfish | 128 | 64 | Yes | No |
MCRYPT_BLOWFISH_192 | Blowfish | 192 | 64 | Yes | |
MCRYPT_BLOWFISH_256 | Blowfish | 256 | 64 | Yes | No |
MCRYPT_BLOWFISH_448 | Blowfish | 448 | 64 | Yes | No |
MCRYPT_CAST_128 | CAST (Carlisle Adams and Stafford Tavares) | 128 | 64 | Yes | Yes |
MCRYPT_CAST_256 | CAST | 256 | 128 | Yes | Yes |
MCRYPT_CRYPT | One-rotor Unix crypt | 104 | 8 | Yes | |
MCRYPT_ENIGNA | One-rotor Unix crypt | 104 | 8 | No | Yes |
MCRYPT_DES | U.S. Data Encryption Standard | 56 | 64 | Yes | Yes |
MCRYPT_GOST | Soviet Gosudarstvennyi Standard ("Government Standard") | 256 | 64 | Yes | Yes |
MCRYPT_IDEA | International Data Encryption Algorithm | 128 | 64 | Yes | Yes |
MCRYPT_LOKI97 | LOKI97 (Lawrie Brown, Josef Pieprzyk) | 128, 192, or 256 | 64 | Yes | Yes |
MCRYPT_MARS | MARS (IBM) | 128-448 | 128 | No | Yes |
MCRYPT_PANAMA | PANAMA (Joan Daemen, Craig Clapp) | - | Stream | No | Yes |
MCRYPT_RC2 | Rivest Cipher 2 | 8-1024 | 64 | No | Yes |
MCRYPT_RC2_1024 | Rivest Cipher 2 | 1024 | 64 | Yes | No |
MCRYPT_RC2_128 | Rivest Cipher 2 | 128 | 64 | Yes | No |
MCRYPT_RC2_256 | Rivest Cipher 2 | 256 | 64 | Yes | No |
MCRYPT_RC4 | Rivest Cipher 4 | Up to 2048 | Stream | Yes | No |
MCRYPT_ARCFOUR | Non-trademarked RC4 compatible | Up to 2048 | Stream | No | Yes |
MCRYPT_ARCFOUR_IV | Arcfour with Initialization Vector | Up to 2048 | Stream | No | Yes |
MCRYPT_RC6 | Rivest Cipher 6 | 128, 192, or 256 | 128 | No | Yes |
MCRYPT_RC6_128 | Rivest Cipher 6 | 128 | 128 | Yes | No |
MCRYPT_RC6_192 | Rivest Cipher 6 | 192 | 128 | Yes | No |
MCRYPT_RC6_256 | Rivest Cipher 6 | 256 | 128 | Yes | No |
MCRYPT_RIJNDAEL_128 | Rijndael (Joan Daemen, Vincent Rijmen) | 128 | 128 | Yes | Yes |
MCRYPT_RIJNDAEL_192 | Rijndael | 192 | 192 | Yes | Yes |
MCRYPT_RIJNDAEL_256 | Rijndael | 256 | 256 | Yes | Yes |
MCRYPT_SAFERPLUS | SAFER+ (based on SAFER) | 128, 192, or 256 | 128 | Yes | Yes |
MCRYPT_SAFER_128 | Secure And Fast Encryption Routine with strengthened key schedule | 128 | 64 | Yes | Yes |
MCRYPT_SAFER_64 | Secure And Fast Encryption Routine with strengthened key | 64 | 64 | Yes | Yes |
MCRYPT_SERPENT | Serpent (Ross Anderson, Eli Biham, Lars Knudsen) | 128, 192, or 256 | 128 | No | Yes |
MCRYPT_SERPENT_128 | Serpent | 128 | 128 | Yes | No |
MCRYPT_SERPENT_192 | Serpent | 192 | 128 | Yes | No |
MCRYPT_SERPENT_256 | Serpent | 256 | 128 | Yes | No |
MCRYPT_SKIPJACK | U.S. NSA Clipper Escrowed Encryption Standard | 80 | 64 | No | Yes |
MCRYPT_TWOFISH | Twofish (Counterpane Systems) | 128, 192, or 256 | 128 | No | Yes |
MCRYPT_TWOFISH_128 | Twofish | 128 | 128 | Yes | No |
MCRYPT_TWOFISH_192 | Twofish | 192 | 128 | Yes | No |
MCRYPT_TWOFISH_256 | Twofish | 256 | 128 | Yes | No |
MCRYPT_WAKE | Word Auto Key Encryption (David Wheeler) | 256 | 32 | No | Yes |
MCRYPT_XTEA | Extended Tiny Encryption Algorithm (David Wheeler, Roger Needham) | 128 | 64 | Yes | Yes |
The different modes are appropriate in different circumstances. Cipher Block Chaining (CBC) mode encrypts the data in blocks, and uses the encrypted value of each block (as well as the key) to compute the encrypted value of the next block. The initialization vector affects the encrypted value of the first block. Cipher Feedback (CFB) and Output Feedback (OFB) also use an initialization vector, but they encrypt data in units smaller than the block size. Note that OFB mode has security problems if you encrypt data in smaller units than its block size. Electronic Code Book (ECB) mode encrypts data in discreet blocks that don't depend on each other. ECB mode doesn't use an initialization vector. It is also less secure than other modes for repeated use, because the same plaintext with a given key always produces the same ciphertext. Constants to set each mode are listed in table below.
Mode constant | Description |
---|---|
MCRYPT_MODE_ECB | Electronic Code Book mode |
MCRYPT_MODE_CBC | Cipher Block Chaining mode |
MCRYPT_MODE_CFB | Cipher Feedback mode |
MCRYPT_MODE_OFB | Output Feedback mode with 8 bits of feedback |
MCRYPT_MODE_NOFB | Output Feedback mode with n bits of feedback, where n is the block size of the algorithm used (libmcrypt 2.4 and higher only) |
MCRYPT_MODE_STREAM | Stream Cipher mode, for algorithms such as RC4 and WAKE (libmcrypt 2.4 and higher only) |
Source : java-samples.com
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment