Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions
Cryptographer Class Reference

Public Member Functions

 __construct (AnalyticsToken $analyticsToken, EncodedContextFactory $encodedContextFactory)
 
 encode ($source)
 

Detailed Description

Class for encrypting data.

Definition at line 13 of file Cryptographer.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( AnalyticsToken  $analyticsToken,
EncodedContextFactory  $encodedContextFactory 
)
Parameters
AnalyticsToken$analyticsToken
EncodedContextFactory$encodedContextFactory

Definition at line 38 of file Cryptographer.php.

41  {
42  $this->analyticsToken = $analyticsToken;
43  $this->encodedContextFactory = $encodedContextFactory;
44  }

Member Function Documentation

◆ encode()

encode (   $source)

Encrypt input data.

Parameters
string$source
Returns
EncodedContext
Exceptions
LocalizedException

Definition at line 53 of file Cryptographer.php.

54  {
55  if (!is_string($source)) {
56  try {
57  $source = (string)$source;
58  } catch (\Exception $e) {
59  throw new LocalizedException(
60  __(
61  'The data is invalid. '
62  . 'Enter the data as a string or data that can be converted into a string and try again.'
63  )
64  );
65  }
66  } elseif (!$source) {
67  throw new LocalizedException(__('The data is invalid. Enter the data as a string and try again.'));
68  }
69  if (!$this->validateCipherMethod($this->cipherMethod)) {
70  throw new LocalizedException(__('The data is invalid. Use a valid cipher method and try again.'));
71  }
72  $initializationVector = $this->getInitializationVector();
73 
74  $encodedContext = $this->encodedContextFactory->create([
75  'content' => openssl_encrypt(
76  $source,
77  $this->cipherMethod,
78  $this->getKey(),
79  OPENSSL_RAW_DATA,
80  $initializationVector
81  ),
82  'initializationVector' => $initializationVector,
83  ]);
84 
85  return $encodedContext;
86  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$source
Definition: source.php:23
__()
Definition: __.php:13

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