Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions
Mcrypt Class Reference
Inheritance diagram for Mcrypt:
EncryptionAdapterInterface

Public Member Functions

 __construct (string $key, string $cipher=MCRYPT_BLOWFISH, string $mode=MCRYPT_MODE_ECB, string $initVector=null)
 
 __destruct ()
 
 getCipher ()
 
 getMode ()
 
 getInitVector ()
 
 getHandle ()
 
 encrypt (string $data)
 
 decrypt (string $data)
 

Detailed Description

Mcrypt adapter for decrypting values using legacy ciphers

Definition at line 14 of file Mcrypt.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( string  $key,
string  $cipher = MCRYPT_BLOWFISH,
string  $mode = MCRYPT_MODE_ECB,
string  $initVector = null 
)

Mcrypt constructor.

Parameters
string$key
string$cipher
string$mode
string$initVector
Exceptions

Definition at line 46 of file Mcrypt.php.

51  {
52  $this->cipher = $cipher;
53  $this->mode = $mode;
54  // @codingStandardsIgnoreLine
55  $this->handle = @mcrypt_module_open($cipher, '', $mode, '');
56  try {
57  // @codingStandardsIgnoreLine
58  $maxKeySize = @mcrypt_enc_get_key_size($this->handle);
59  if (strlen($key) > $maxKeySize) {
60  throw new \Magento\Framework\Exception\LocalizedException(
61  new \Magento\Framework\Phrase('Key must not exceed %1 bytes.', [$maxKeySize])
62  );
63  }
64  // @codingStandardsIgnoreLine
65  $initVectorSize = @mcrypt_enc_get_iv_size($this->handle);
66  if (null === $initVector) {
67  /* Set vector to zero bytes to not use it */
68  $initVector = str_repeat("\0", $initVectorSize);
69  } elseif (!is_string($initVector) || strlen($initVector) != $initVectorSize) {
70  throw new \Magento\Framework\Exception\LocalizedException(
71  new \Magento\Framework\Phrase(
72  'Init vector must be a string of %1 bytes.',
74  )
75  );
76  }
77  $this->initVector = $initVector;
78  } catch (\Exception $e) {
79  // @codingStandardsIgnoreLine
80  @mcrypt_module_close($this->handle);
81  throw new \Magento\Framework\Exception\LocalizedException(new \Magento\Framework\Phrase($e->getMessage()));
82  }
83  // @codingStandardsIgnoreLine
84  @mcrypt_generic_init($this->handle, $key, $initVector);
85  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$initVectorSize

◆ __destruct()

__destruct ( )

Destructor frees allocated resources

Definition at line 90 of file Mcrypt.php.

91  {
92  // @codingStandardsIgnoreStart
93  @mcrypt_generic_deinit($this->handle);
94  @mcrypt_module_close($this->handle);
95  // @codingStandardsIgnoreEnd
96  }

Member Function Documentation

◆ decrypt()

decrypt ( string  $data)

Decrypt a string

Parameters
string$data
Returns
string

Implements EncryptionAdapterInterface.

Definition at line 160 of file Mcrypt.php.

160  : string
161  {
162  if (strlen($data) == 0) {
163  return $data;
164  }
165  // @codingStandardsIgnoreLine
166  $data = @mdecrypt_generic($this->handle, $data);
167  /*
168  * Returned string can in fact be longer than the unencrypted string due to the padding of the data
169  * @link http://www.php.net/manual/en/function.mdecrypt-generic.php
170  */
171  $data = rtrim($data, "\0");
172  return $data;
173  }

◆ encrypt()

encrypt ( string  $data)

Encrypt a string

Parameters
string$dataString to encrypt
Returns
string
Exceptions

Implements EncryptionAdapterInterface.

Definition at line 145 of file Mcrypt.php.

145  : string
146  {
147  if (strlen($data) == 0) {
148  return $data;
149  }
150  // @codingStandardsIgnoreLine
151  return @mcrypt_generic($this->getHandle(), $data);
152  }

◆ getCipher()

getCipher ( )

Retrieve a name of currently used cryptographic algorithm

Returns
string

Definition at line 103 of file Mcrypt.php.

103  : string
104  {
105  return $this->cipher;
106  }

◆ getHandle()

getHandle ( )

Get the current mcrypt handle

Returns
resource

Definition at line 133 of file Mcrypt.php.

134  {
135  return $this->handle;
136  }

◆ getInitVector()

getInitVector ( )

Retrieve an actual value of initial vector that has been used to initialize a cipher

Returns
string

Definition at line 123 of file Mcrypt.php.

123  : ?string
124  {
125  return $this->initVector;
126  }

◆ getMode()

getMode ( )

Mode in which cryptographic algorithm is running

Returns
string

Definition at line 113 of file Mcrypt.php.

113  : string
114  {
115  return $this->mode;
116  }

The documentation for this class was generated from the following file: