[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Source view] [Print] [Project Stats]
Pure-PHP implementation of Triple DES. Uses mcrypt, if available, and an internal implementation, otherwise. Operates in the EDE3 mode (encrypt-decrypt-encrypt).
Author: | Jim Wigginton <[email protected]> |
Copyright: | 2007 Jim Wigginton |
License: | http://www.opensource.org/licenses/mit-license.html MIT License |
File Size: | 457 lines (14 kb) |
Included or required: | 0 times |
Referenced: | 0 times |
Includes or requires: | 0 files |
TripleDES:: (11 methods):
__construct()
isValidEngineHelper()
setIV()
setKeyLength()
setKey()
encrypt()
decrypt()
enableContinuousBuffer()
disableContinuousBuffer()
setupKey()
setPreferredEngine()
__construct($mode) X-Ref |
Default Constructor. Determines whether or not the mcrypt or OpenSSL extensions should be used. $mode could be: - ecb - cbc - ctr - cfb - ofb - 3cbc - cbc3 (same as cbc) param: string $mode |
isValidEngineHelper($engine) X-Ref |
Test for engine validity This is mainly just a wrapper to set things up for \phpseclib3\Crypt\Common\SymmetricKey::isValidEngine() param: int $engine return: bool |
setIV($iv) X-Ref |
Sets the initialization vector. SetIV is not required when \phpseclib3\Crypt\Common\SymmetricKey::MODE_ECB is being used. param: string $iv |
setKeyLength($length) X-Ref |
Sets the key length. Valid key lengths are 128 and 192 bits. If you want to use a 64-bit key use DES.php param: int $length |
setKey($key) X-Ref |
Sets the key. Triple DES can use 128-bit (eg. strlen($key) == 16) or 192-bit (eg. strlen($key) == 24) keys. DES also requires that every eighth bit be a parity bit, however, we'll ignore that. param: string $key |
encrypt($plaintext) X-Ref |
Encrypts a message. param: string $plaintext return: string $cipertext |
decrypt($ciphertext) X-Ref |
Decrypts a message. param: string $ciphertext return: string $plaintext |
enableContinuousBuffer() X-Ref |
Treat consecutive "packets" as if they are a continuous buffer. Say you have a 16-byte plaintext $plaintext. Using the default behavior, the two following code snippets will yield different outputs: <code> echo $des->encrypt(substr($plaintext, 0, 8)); echo $des->encrypt(substr($plaintext, 8, 8)); </code> <code> echo $des->encrypt($plaintext); </code> The solution is to enable the continuous buffer. Although this will resolve the above discrepancy, it creates another, as demonstrated with the following: <code> $des->encrypt(substr($plaintext, 0, 8)); echo $des->decrypt($des->encrypt(substr($plaintext, 8, 8))); </code> <code> echo $des->decrypt($des->encrypt(substr($plaintext, 8, 8))); </code> With the continuous buffer disabled, these would yield the same output. With it enabled, they yield different outputs. The reason is due to the fact that the initialization vector's change after every encryption / decryption round when the continuous buffer is enabled. When it's disabled, they remain constant. Put another way, when the continuous buffer is enabled, the state of the \phpseclib3\Crypt\DES() object changes after each encryption / decryption round, whereas otherwise, it'd remain constant. For this reason, it's recommended that continuous buffers not be used. They do offer better security and are, in fact, sometimes required (SSH uses them), however, they are also less intuitive and more likely to cause you problems. |
disableContinuousBuffer() X-Ref |
Treat consecutive packets as if they are a discontinuous buffer. The default behavior. |
setupKey() X-Ref |
Creates the key schedule |
setPreferredEngine($engine) X-Ref |
Sets the internal crypt engine param: int $engine |
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |