Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Attributes
Crypt Class Reference

Public Member Functions

 __construct ( $key, $cipher=MCRYPT_BLOWFISH, $mode=MCRYPT_MODE_ECB, $initVector=false)
 
 getCipher ()
 
 getMode ()
 
 getInitVector ()
 
 encrypt ($data)
 
 decrypt ($data)
 

Protected Attributes

 $_cipher
 
 $_mode
 
 $_initVector
 

Detailed Description

Class encapsulates cryptographic algorithm

@api

Deprecated:
Since
100.0.2

Definition at line 18 of file Crypt.php.

Constructor & Destructor Documentation

◆ __construct()

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

Constructor

Parameters
string$keySecret encryption key. It's unsafe to store encryption key in memory, so no getter for key exists.
string$cipherCipher algorithm (one of the MCRYPT_ciphername constants)
string$modeMode of cipher algorithm (MCRYPT_MODE_modeabbr constants)
string | bool$initVectorInitial vector to fill algorithm blocks. TRUE generates a random initial vector. FALSE fills initial vector with zero bytes to not use it.
Exceptions

Definition at line 54 of file Crypt.php.

59  {
60  if (true === $initVector) {
61  // @codingStandardsIgnoreStart
62  $handle = @mcrypt_module_open($cipher, '', $mode, '');
63  $initVectorSize = @mcrypt_enc_get_iv_size($handle);
64  // @codingStandardsIgnoreEnd
65 
66  /* Generate a random vector from human-readable characters */
67  $allowedCharacters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
68  $initVector = '';
69  for ($i = 0; $i < $initVectorSize; $i++) {
70  $initVector .= $allowedCharacters[rand(0, strlen($allowedCharacters) - 1)];
71  }
72  // @codingStandardsIgnoreStart
73  @mcrypt_generic_deinit($handle);
74  @mcrypt_module_close($handle);
75  // @codingStandardsIgnoreEnd
76  }
77 
78  $this->mcrypt = new \Magento\Framework\Encryption\Adapter\Mcrypt(
79  $key,
80  $cipher,
81  $mode,
82  $initVector === false ? null : $initVector
83  );
84  }
$initVector
$initVectorSize
if($exist=($block->getProductCollection() && $block->getProductCollection() ->getSize())) $mode
Definition: grid.phtml:15
$handle
$i
Definition: gallery.phtml:31

Member Function Documentation

◆ decrypt()

decrypt (   $data)

Decrypt a data

Parameters
string$dataString to decrypt
Returns
string

Definition at line 137 of file Crypt.php.

138  {
139  return $this->mcrypt->decrypt($data);
140  }

◆ encrypt()

encrypt (   $data)

Encrypt a data

Parameters
string$dataString to encrypt
Returns
string

Definition at line 122 of file Crypt.php.

123  {
124  if (strlen($data) == 0) {
125  return $data;
126  }
127  // @codingStandardsIgnoreLine
128  return @mcrypt_generic($this->mcrypt->getHandle(), $data);
129  }

◆ getCipher()

getCipher ( )

Retrieve a name of currently used cryptographic algorithm

Returns
string

Definition at line 91 of file Crypt.php.

92  {
93  return $this->mcrypt->getCipher();
94  }

◆ getInitVector()

getInitVector ( )

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

Returns
string

Definition at line 111 of file Crypt.php.

112  {
113  return $this->mcrypt->getInitVector();
114  }

◆ getMode()

getMode ( )

Mode in which cryptographic algorithm is running

Returns
string

Definition at line 101 of file Crypt.php.

102  {
103  return $this->mcrypt->getMode();
104  }

Field Documentation

◆ $_cipher

$_cipher
protected

Definition at line 23 of file Crypt.php.

◆ $_initVector

$_initVector
protected

Definition at line 33 of file Crypt.php.

◆ $_mode

$_mode
protected

Definition at line 28 of file Crypt.php.


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