Esempio n. 1
0
 /**
  * Encrypt value before saving
  *
  * @return void
  */
 public function beforeSave()
 {
     $this->_dataSaveAllowed = false;
     $value = (string) $this->getValue();
     // don't save value, if an obscured value was received. This indicates that data was not changed.
     if (!preg_match('/^\\*+$/', $value) && !empty($value)) {
         $this->_dataSaveAllowed = true;
         $encrypted = $this->_encryptor->encrypt($value);
         $this->setValue($encrypted);
     }
 }
Esempio n. 2
0
 /**
  * Encrypt value before saving
  *
  * @return void
  */
 public function beforeSave()
 {
     $value = (string) $this->getValue();
     // don't change value, if an obscured value came
     if (preg_match('/^\\*+$/', $this->getValue())) {
         $value = $this->getOldValue();
     }
     if (!empty($value)) {
         $encrypted = $this->_encryptor->encrypt($value);
         if ($encrypted) {
             $this->setValue($encrypted);
         }
     }
 }
Esempio n. 3
0
 /**
  * Gather saved credit card numbers from sales order payments and re-encrypt them
  *
  * @return void
  */
 protected function _reEncryptCreditCardNumbers()
 {
     $table = $this->getTable('sales_order_payment');
     $select = $this->getConnection()->select()->from($table, ['entity_id', 'cc_number_enc']);
     $attributeValues = $this->getConnection()->fetchPairs($select);
     // save new values
     foreach ($attributeValues as $valueId => $value) {
         $this->getConnection()->update($table, ['cc_number_enc' => $this->encryptor->encrypt($this->encryptor->decrypt($value))], ['entity_id = ?' => (int) $valueId]);
     }
 }
Esempio n. 4
0
 /**
  * Process additional data before save config
  *
  * @return $this
  * @throws \Magento\Framework\Model\Exception
  */
 protected function _beforeSave()
 {
     $value = $this->getValue();
     if (is_array($value) && !empty($value['delete'])) {
         $this->setValue('');
         $this->_certFactory->create()->loadByWebsite($this->getScopeId())->delete();
     }
     if (!isset($_FILES['groups']['tmp_name'][$this->getGroupId()]['fields'][$this->getField()]['value'])) {
         return $this;
     }
     $tmpPath = $this->_tmpDirectory->getRelativePath($_FILES['groups']['tmp_name'][$this->getGroupId()]['fields'][$this->getField()]['value']);
     if ($tmpPath && $this->_tmpDirectory->isExist($tmpPath)) {
         if (!$this->_tmpDirectory->stat($tmpPath)['size']) {
             throw new \Magento\Framework\Model\Exception(__('The PayPal certificate file is empty.'));
         }
         $this->setValue($_FILES['groups']['name'][$this->getGroupId()]['fields'][$this->getField()]['value']);
         $content = $this->_encryptor->encrypt($this->_tmpDirectory->readFile($tmpPath));
         $this->_certFactory->create()->loadByWebsite($this->getScopeId())->setContent($content)->save();
     }
     return $this;
 }
 /**
  * Save the configuration value in both core and module db tables.
  *
  * @param $path
  * @param $scopeId
  * @param $value
  * @param string $type
  */
 protected function _saveConfig($path, $scopeId, $value, $type = self::TYPE_NORMAL)
 {
     // do not save config if path validation fails.
     if (!($fullPathParts = $this->_validateFullPath($path))) {
         return;
     }
     if ($type === self::TYPE_ENCRYPTED) {
         $value = $this->_encryptor->encrypt($value);
     }
     // get the path from the parts of path
     $path = implode('/', array_slice($fullPathParts, 1, 3));
     $this->_coreConfigResource->saveConfig($path, $value, $fullPathParts[0], $scopeId);
     $this->_configModel->setData(['scope_type' => $fullPathParts[0], 'scope_id' => $scopeId, 'path' => $path, 'value' => $value]);
     $this->_configModel->save();
     $this->_configModel->clearInstance();
 }
Esempio n. 6
0
 /**
  * Encrypt data
  *
  * @param string $data
  * @return string
  */
 public function encrypt($data)
 {
     return $this->_encryptor->encrypt($data);
 }
Esempio n. 7
0
 /**
  * Encrypt password
  *
  * @param   string $password
  * @return  string
  */
 public function encryptPassword($password)
 {
     return $this->_encryptor->encrypt($password);
 }
Esempio n. 8
0
 /**
  * Decrypt value
  *
  * @param string $value
  * @return string
  */
 public function decrypt($value)
 {
     return $this->encryptor->encrypt($value);
 }