嗨,有一个 xml,我在其中分配由第三方获得的密码值。我想蒙蔽其中。我想隐藏该密码。代码在php.ini中。 php 可以屏蔽密码吗?
最佳答案
您可以使用以下方法加密密码:
define('SALT', 'atopsecretphrase');
function encrypt($text)
{
return trim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, SALT, $text, MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND))));
}
function decrypt($text)
{
return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, SALT, base64_decode($text), MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND)));
}
$encryptedmessage = encrypt("mypassword");
echo decrypt($encryptedmessage);
关于php - php 中的隐藏密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11670624/