您可以使用Magento 2的加密或解密任何字符串功能。
您可以使用Magento \ Framework \ Encryption \ EncryptorInterface接口进行加密或解密密码或信用卡数据或信用卡数据或任何值。


例如,您可以使用以下方式加密密码,
<?php
use Magento\Framework\Encryption\EncryptorInterface;
public function __construct(
EncryptorInterface $encryptor
) {
$this->encryptor = $encryptor;
}
/**
* Encrypt password
*
* @param string $password
* @return string
*/
public function encryptPassword($password)
{
return $this->encryptor->encrypt($password);
}
/**
* Decrypt password
*
* @param string $password
* @return string
*/
public function decryptPassword($password)
{
return $this->encryptor->decrypt($password);
}
在代码的其它地方可以这样调用,加密如下
$this->encryptPassword(“PASSWORD”)
解密如下,
$this->decryptPassword(“PASSWORD”)