| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- namespace App\Common\Library;
- class DES
- {
- private $key;
- private $encryptor;
- public function __construct($key)
- {
- $this->key = $this->complement($key);
- $this->encryptor = new Encryptor($key);
- }
- public function complement($key)
- {
- if (strlen($key) < 8) {
- $len = strlen($key) % 8;
- if ($len == 0) {
- return $key;
- } else {
- $j = 8 - $len;
- for ($i = 0; $i < $j; $i++) {
- $key .= "\0";
- }
- return $key;
- }
- } else {
- return $key;
- }
- }
- /**
- * @param $encrypt
- * @return string
- */
- public function encrypt($encrypt)
- {
- return $this->encryptor->encrypt($encrypt);
- }
- /**
- * @param $decrypt
- * @return string
- */
- public function decrypt($decrypt)
- {
- return $this->encryptor->decrypt($decrypt);
- }
- }
|