Skip to content

Commit 2f737f9

Browse files
committed
Now having the DES implementations extend from the
abstract and perform the new key processing
1 parent 505c21d commit 2f737f9

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

src/Robin/Ntlm/Crypt/Des/McryptDesEncrypter.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@
1111
use InvalidArgumentException;
1212
use Robin\Ntlm\Crypt\CipherMode;
1313
use Robin\Ntlm\Crypt\Exception\CryptographicFailureException;
14-
use UnexpectedValueException;
1514

1615
/**
1716
* An engine used to encrypt data using the DES standard algorithm and
1817
* implemented using the PHP "mcrypt" extension.
1918
*
2019
* @link http://php.net/mcrypt
2120
*/
22-
class McryptDesEncrypter implements DesEncrypterInterface
21+
class McryptDesEncrypter extends AbstractDesEncrypter implements DesEncrypterInterface
2322
{
2423

2524
/**
@@ -52,6 +51,8 @@ public function encrypt($key, $data, $mode, $initialization_vector)
5251
throw new InvalidArgumentException('Unknown cipher mode "'. $mode .'"');
5352
}
5453

54+
$key = $this->processKey($key);
55+
5556
$encrypted = mcrypt_encrypt(MCRYPT_DES, $key, $data, $mode, $initialization_vector);
5657

5758
if (false === $encrypted) {

src/Robin/Ntlm/Crypt/Des/OpenSslDesEncrypter.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*
1919
* @link http://php.net/openssl
2020
*/
21-
class OpenSslDesEncrypter implements DesEncrypterInterface
21+
class OpenSslDesEncrypter extends AbstractDesEncrypter implements DesEncrypterInterface
2222
{
2323

2424
/**
@@ -65,9 +65,13 @@ class OpenSslDesEncrypter implements DesEncrypterInterface
6565
*
6666
* @param bool $zero_pad Whether or not to zero-byte pad the data before
6767
* encrypting for some cipher modes.
68+
* @param bool $expand_and_normalize_keys Whether or not to expand and
69+
* normalize the key before encrypting.
6870
*/
69-
public function __construct($zero_pad = true)
71+
public function __construct($zero_pad = true, $expand_and_normalize_keys = true)
7072
{
73+
parent::__construct($expand_and_normalize_keys);
74+
7175
$this->zero_pad = $zero_pad;
7276
}
7377

@@ -84,6 +88,8 @@ public function encrypt($key, $data, $mode, $initialization_vector)
8488

8589
$options = $this->getOpenSslEncryptionOptions();
8690

91+
$key = $this->processKey($key);
92+
8793
$encrypted = openssl_encrypt($data, $mode, $key, $options, $initialization_vector);
8894

8995
if (false === $encrypted) {

0 commit comments

Comments
 (0)