암호화 된 구성 값을 어떻게 해독 할 수 있습니까?


12
protected $_paymentData;
protected $_scopeConfig;
protected $logger;

public function __construct(
    \Magento\Framework\Model\Context $context,
    \Magento\Framework\Registry $registry,
    \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory,
    \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory,
    \Magento\Payment\Helper\Data $paymentData,
    \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
    \Magento\Payment\Model\Method\Logger $logger,
    \Magento\Framework\Module\ModuleListInterface $moduleList,
    \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
    \Magento\Directory\Model\CountryFactory $countryFactory,
    \Stripe\Stripe $stripe,
    \Inchoo\Stripe\Model\StripeFactory $stripeFactory,
    array $data = array()
) {
    parent::__construct(
        $context,
        $registry,
        $extensionFactory,
        $customAttributeFactory,
        $paymentData,
        $scopeConfig,
        $logger,
        $moduleList,
        $localeDate,
        null,
        null,
        $data
    );
    $this->_scopeConfig = $scopeConfig;
    $this->logger = $logger;
    $this->initializeData($data);
}
 public function getPaymentKey(){
   $key= $this->_scopeConfig->getValue('payment/webpay/keyid');
    echo $key;
    exit; 
}

에코 결과 : idfrk3-45pfnrkhwneirgplbmisniepssnie : hirtw45 True Key- 'p92GBhcQl7TklHOsWcxBk4eOmL6wpQWBG9nT2Qcf'

답변:


26

마지막으로 암호 해독 코드에서 성공하기 ...

protected $_encryptor;

public function __construct(
    \Magento\Framework\Encryption\EncryptorInterface $encryptor,
) {
    $this->_encryptor = $encryptor;
    parent::__construct($context);
}
$test = 'dfrk3-45pfnrkhwneirgplbmisniepssnie';
$test = $this->_encryptor->decrypt($test);
echo $test;

다른 사람들과 공유하고 도와주세요 ...


빈 값을 반환합니다. 읽을 수있는 형식으로 출력하려면 어떻게해야합니까?
— Emipro Technologies Pvt. (주)

이슈 코드를 공유 할 수 있습니까?
— Magento2 Devloper

20

\Magento\Framework\App\Config\ScopeConfigInterface::getValue해독 된 값을 반환합니다. 때 ScopeConfigInterface::getValue암호화 된 값을 반환 구성 옵션이 설정은 잘못 . 암호화 된 구성 값의 올바른 구현은 다음과 같습니다.

공급 업체 / 모듈 /etc/adminhtml/system.xml

여기서 payment/webpay/keyid중요한 사항은에 대한 field보유 type="obscure"및 사용 Magento\Config\Model\Config\Backend\Encrypted을 보장하는 경로에 모호한 구성 값을 추가 합니다 backend_model. Magento가 마스크 양식 필드를 사용하고 저장시 사용자 입력을 암호화하는 방법입니다.

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
    <system>
        <section id="payment">
            <group id="webpay">
                <field id="keyid" translate="label" type="obscure" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>Key Id</label>
                    <backend_model>Magento\Config\Model\Config\Backend\Encrypted</backend_model>
                </field>
            </group>
        </section>
    </system>
</config>

공급 업체 / 모듈 /etc/config.xml

backend_model="Magento\Config\Model\Config\Backend\Encrypted"여기에 추가하면 Magento에게 다음과 같이 검색 할 때 구성 값을 해독해야합니다.ScopeConfigInterface::getValue

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
    <default>
        <payment>
            <webpay>
                <keyid backend_model="Magento\Config\Model\Config\Backend\Encrypted" />
            </webpay>
        </payment>
    </default>
</config>

공급 업체 / 모듈 /etc/di.xml

그러면 민감한 어레이에 구성 경로가 추가되고 상점 구성을 덤프 할 때 경로 값이 포함되지 않습니다.

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Config\Model\Config\TypePool">
        <arguments>
            <argument name="sensitive" xsi:type="array">
                <item name="payment/webpay/keyid" xsi:type="string">1</item>
            </argument>
        </arguments>
    </type>
</config>

이것이 작동하지 않는 시나리오가있는 것 같습니다. 제 경우에는 이전에 작동했고 필드를 포함 된 그룹 xml 구성으로 옮긴 후에 파산했습니다. 위의 제안은 구현되었지만 작동하지 않음
— snez

@snez 구성을 이동 한 후 다시 저장하려고 했습니까?
— 로마 Snitko

5

n98-magerun2.phar를 설치 한 경우 다음과 같은 방법으로 암호 해독 된 구성 값을 얻을 수 있습니다.

php bin/n98-magerun2.phar config:store:get --decrypt payment/webpay/keyid

명령 행에서 다음과 같이 암호화 된 구성 값을 설정할 수도 있습니다.

php bin/n98-magerun2.phar config:store:set --encrypt payment/webpay/keyid NEW_KEY_ID_VALUE_HERE

여기에서 n98-magerun2.phar를 얻을 수 있습니다 : https://github.com/netz98/n98-magerun2


2
N98이 가장 위대한 것이 아닌가?
— William Tran

이것은 n98-magerun (Magento 1 용)
— CCBlackburn

0

You can try with below method for payment encryption method to get value,

\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,아래 클래스 경로 로 바꿔야 \Magento\Payment\Gateway\ConfigInterface 합니다.

   <?php
/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Vendor\Module\Gateway\Http;

use Magento\Payment\Gateway\Http\TransferBuilder;
use Magento\Payment\Gateway\Http\TransferFactoryInterface;
use Magento\Payment\Gateway\Http\TransferInterface;
use Magento\Payment\Gateway\ConfigInterface;

class TransferFactory implements TransferFactoryInterface
{
    private $config;

    private $transferBuilder;

    public function __construct(
        ConfigInterface $config,
        TransferBuilder $transferBuilder
    ) {
        $this->config = $config;
        $this->transferBuilder = $transferBuilder;
    }


    public function getPaymentKey()
    {
        echo $this->config->getValue('payment/webpay/keyid')
    }
}

이것은 당신을 위해 작동합니까?
— Rakesh Jesadiya

치명적인 오류 : E : \ wamp \ www \ magento2_8 \ vendor \ magento \ framework \ ObjectManager \ Factory \ Dynamic \ Developer.php에서 Magento \ Payment \ Gateway \ ConfigInterface 인터페이스를 인스턴스화 할 수 없습니다. 73 행
— Magento2 Devloper

문제를 해결 했습니까?
— Rakesh Jesadiya

치명적인 오류가 발생하지 않음 : E : \ wamp \ www \ magento2_8 \ vendor \ magento \ framework \ ObjectManager \ Factory \ Dynamic \ De‌veloper.php에서 Magento \ Payment \ Gateway \ ConfigInterface 인터페이스를 인스턴스화 할 수 없습니다.
— Magento2 Devloper

위의 업데이트 된 코드로 시도하고 var 폴더를 제거하십시오.
— Rakesh Jesadiya

0

일부 키를 사용하여 일부 값을 해독하려는 경우 : magento 프로젝트의 루트에있는 아래의 코드를 decrypt-config-value.php에 입력하십시오.

<?php

use Magento\Framework\App\Bootstrap;
require __DIR__ . '/app/bootstrap.php';

$bootstrap = Bootstrap::create(BP, $_SERVER);

$obj = $bootstrap->getObjectManager();

$state = $obj->get('Magento\Framework\App\State');
$state->setAreaCode('frontend');


######################################################################################################################

/**
 * @var \Magento\Framework\Encryption\EncryptorInterfaceFactory $ef
 */
$ef = $obj->get('Magento\Framework\Encryption\EncryptorInterfaceFactory');

class CustomDeploymentConfig extends \Magento\Framework\App\DeploymentConfig {
    public function get($key = null, $defaultValue = null)
    {
        return '8343d1c27ee612c73131c0ec693ed86e';
    }
}

/**
 * @var CustomDeploymentConfig $d
 */
$d = $obj->get(CustomDeploymentConfig::class);

/**
 * @var \Magento\Framework\Encryption\EncryptorInterface $e
 */
$e = $ef->create(['deploymentConfig' => $d]);

echo ">>>", $e->decrypt('encripted-value-here'), "<<<\n";

콘솔을 사용하여 php decrypt-config-value.php 를 실행하거나 브라우저를 사용하여 //yourwebsite.com/decrypt-config-value.php 를 실행하십시오 .


-1

json 디코드 값을 아래 코드로 시도하십시오.

class Paymentmodule
{
    protected $jsonEncoder;
    protected $jsonDecoder;

    public function __construct(
        ..//
        \Magento\Framework\Json\DecoderInterface $jsonDecoder
    ) {
        ..//
        $this->jsonDecoder = $jsonDecoder;
    }

    public function getPaymentKey()
    {
        $key= $this->_scopeConfig->getValue('payment/webpay/keyid');
        $config = $this->jsonDecoder->decode($key);
        echo $key;
    }

}

1
디코딩 실패 : 구문 오류 "; i : 1; s : 10720 :"# 0 E : \ wamp \ www \ magento2_8 \ vendor \ magento \ framework \ Json \ Decoder.php (20) : Zend_Json :: decode ( '0 : 2 : 234SyEIM4aj ... ') # 1 E : \ wamp \ www \ magento2_8 \ vendor \ magento \ module-checkout \ Controller \ Onepage \ Success.php (58) : Magento \ Framework \ Json \ Decoder-> decode (' 0 : 2 : 234SyEIM4aj ... ')
— Magento2 Devloper

이 오류에 대한 아이디어가 있습니까?
— Magento2 Devloper

나는이 지불 방법입니다 때문에, 내가 간단한 쿼리에 대한 위의 방법을 위해 일한, 그것에 대해 아무 생각이
— 케쉬 Jesadiya을

구문 오류 다른 유형을 정의한다고 생각합니다.
— Magento2 Devloper

간단한 쿼리에서 잘 작동합니까 ??
— Magento2 Devloper
당사 사이트를 사용함과 동시에 당사의 쿠키 정책과 개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.