/** * {@inheritdoc} */ public function handle(Record $recordToHandle, Record $oppositeRecord) { $value = $recordToHandle->getValue('value'); if (!$value) { return; } $this->validate($recordToHandle); $parts = explode(':', $value, 4); $partsCount = count($parts); if ($partsCount == 4) { $initVector = $parts[2]; $encryptedValue = $parts[3]; $mode = MCRYPT_MODE_CBC; $cypher = MCRYPT_RIJNDAEL_128; } else { $initVector = false; $encryptedValue = $value; $mode = MCRYPT_MODE_ECB; $cypher = MCRYPT_BLOWFISH; } $crypt = $this->cryptFactory->create(['key' => $this->cryptKey, 'cipher' => $cypher, 'mode' => $mode, 'initVector' => $initVector]); $decryptedValue = trim($crypt->decrypt(base64_decode((string) $encryptedValue))); $encodedValue = $this->encryptor->encrypt($decryptedValue); $recordToHandle->setValue('value', $encodedValue); }
/** * Instantiate crypt model * * @param string|null $key NULL value means usage of the default key specified on constructor * @return \Magento\Framework\Encryption\Crypt */ protected function _getCrypt($key = null) { if ($key === null) { if (!$this->_crypt) { $this->_crypt = $this->_cryptFactory->create(array('key' => $this->_cryptKey)); } return $this->_crypt; } else { return $this->_cryptFactory->create(array('key' => $key)); } }