class MCrypt in DRD Agent 4.0.x
Same name and namespace in other branches
- 8.3 src/Crypt/Method/MCrypt.php \Drupal\drd_agent\Crypt\Method\MCrypt
Provides MCrypt encryption functionality.
Hierarchy
- class \Drupal\drd_agent\Crypt\BaseMethod implements BaseMethodInterface
- class \Drupal\drd_agent\Crypt\Method\MCrypt
Expanded class hierarchy of MCrypt
2 string references to 'MCrypt'
- Base::getMethods in src/
Crypt/ Base.php - Get a list of crypt methods, either just their ids or instances of each.
- MCrypt::getLabel in src/
Crypt/ Method/ MCrypt.php - Get the crypt method label.
File
- src/
Crypt/ Method/ MCrypt.php, line 14
Namespace
Drupal\drd_agent\Crypt\MethodView source
class MCrypt extends BaseMethod {
private $cipher;
private $mode;
private $iv;
private $password;
/**
* {@inheritdoc}
*/
public function __construct(ContainerInterface $container, array $settings = []) {
parent::__construct($container);
$this->cipher = $settings['cipher'] ?? 'rijndael-256';
$this->mode = $settings['mode'] ?? 'cbc';
$this->password = $settings['password'] ?? '';
}
/**
* {@inheritdoc}
*/
public function getLabel() : string {
return 'MCrypt';
}
/**
* {@inheritdoc}
*/
public function getCipher() : string {
return $this->cipher;
}
/**
* {@inheritdoc}
*/
public function getPassword() : string {
return base64_decode($this->password);
}
/**
* {@inheritdoc}
*/
public function isAvailable() : bool {
return function_exists('mcrypt_encrypt');
}
/**
* {@inheritdoc}
*/
public function getCipherMethods() : array {
return [
'rijndael-128',
'rijndael-192',
'rijndael-256',
];
}
/**
* {@inheritdoc}
*/
public function getIv() : string {
if (empty($this->iv)) {
$nonceSize = mcrypt_get_iv_size($this->cipher, $this->mode);
/** @noinspection CryptographicallySecureRandomnessInspection */
$this->iv = mcrypt_create_iv($nonceSize, MCRYPT_DEV_URANDOM);
}
return $this->iv;
}
/**
* {@inheritdoc}
*/
public function encrypt(array $args) : string {
return mcrypt_encrypt($this->cipher, $this
->getPassword(), serialize($args), $this->mode, $this
->getIv());
}
/**
* {@inheritdoc}
*/
public function decrypt($body, $iv) {
$this->iv = $iv;
/** @noinspection UnserializeExploitsInspection */
return unserialize(mcrypt_decrypt($this->cipher, $this
->getPassword(), $body, $this->mode, $this->iv));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BaseMethod:: |
protected | property | ||
BaseMethod:: |
protected | property | ||
BaseMethod:: |
private | function | Callback to encrypt and decrypt files. | |
BaseMethod:: |
public | function |
Encrypt a file. Overrides BaseMethodInterface:: |
|
MCrypt:: |
private | property | ||
MCrypt:: |
private | property | ||
MCrypt:: |
private | property | ||
MCrypt:: |
private | property | ||
MCrypt:: |
public | function |
Decode, decrypt and unserialize arguments from the other end. Overrides BaseMethodInterface:: |
|
MCrypt:: |
public | function |
Encrypt and encode any list of arguments. Overrides BaseMethodInterface:: |
|
MCrypt:: |
public | function |
Get the selected cipher. Overrides BaseMethodInterface:: |
|
MCrypt:: |
public | function |
Get a list of available cipher methods. Overrides BaseMethodInterface:: |
|
MCrypt:: |
public | function |
Get an initialiation vector. Overrides BaseMethodInterface:: |
|
MCrypt:: |
public | function |
Get the crypt method label. Overrides BaseMethodInterface:: |
|
MCrypt:: |
public | function |
Get the password. Overrides BaseMethodInterface:: |
|
MCrypt:: |
public | function |
Find out if the crypt method is available. Overrides BaseMethodInterface:: |
|
MCrypt:: |
public | function |
BaseMethod constructor. Overrides BaseMethod:: |