20 private $analyticsToken;
27 private $cipherMethod =
'AES-256-CBC';
32 private $encodedContextFactory;
40 EncodedContextFactory $encodedContextFactory
43 $this->encodedContextFactory = $encodedContextFactory;
58 }
catch (\Exception $e) {
61 'The data is invalid. ' 62 .
'Enter the data as a string or data that can be converted into a string and try again.' 67 throw new LocalizedException(
__(
'The data is invalid. Enter the data as a string and try again.'));
69 if (!$this->validateCipherMethod($this->cipherMethod)) {
70 throw new LocalizedException(
__(
'The data is invalid. Use a valid cipher method and try again.'));
72 $initializationVector = $this->getInitializationVector();
74 $encodedContext = $this->encodedContextFactory->create([
75 'content' => openssl_encrypt(
82 'initializationVector' => $initializationVector,
85 return $encodedContext;
94 private function getKey()
96 $token = $this->analyticsToken->getToken();
100 return hash(
'sha256',
$token);
108 private function getCipherMethod()
110 return $this->cipherMethod;
118 private function getInitializationVector()
120 $ivSize = openssl_cipher_iv_length($this->getCipherMethod());
121 return openssl_random_pseudo_bytes($ivSize);
130 private function validateCipherMethod($cipherMethod)
132 $methods = openssl_get_cipher_methods();
133 return (
false !== array_search($cipherMethod,
$methods));
elseif(isset( $params[ 'redirect_parent']))
__construct(AnalyticsToken $analyticsToken, EncodedContextFactory $encodedContextFactory)