Python SHA512加密使用PHP

2024-09-29 19:23:51 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我第一次尝试处理python代码。我的客户最近给了我一个python代码:

python -c 'import crypt; print crypt.crypt("Pa55w0rd!", "$6$x88yEvVg")'

用于加密密码,在上面的代码中。你知道吗

密码是Pa55w0rd!盐值为x88yevvvg。我可以用PHP执行上面的代码吗?我试过这样做:

echo exec(`python -c "import crypt;print crypt.crypt('Pa55w0rd!', '\$6\$x88yEvVg\')"`);

谢谢。你知道吗


Tags: 代码importecho密码客户execphpprint
2条回答

使用^{}^{}。你知道吗

例如:

$password = 'Pa55w0rd!';
$salt = '$6$x88yEvVg';
$handle = popen('python -c \'import crypt; print crypt.crypt("' . $password . '", "' . $salt . '")\'', 'r');
$text = fread($handle, 100);
echo $text;
pclose($handle);

你真的需要用python加密吗?根据您的PHP版本,您可以对PHP>;=5.3执行以下操作:

openssl_digest("Pa55w0rd!"."$6$x88yEvVg", "sha512");

对于php5.2或5.1

hash("sha512", "Pa55w0rd!"."$6$x88yEvVg");

这假设您的salt值只是与您的密码值串联在一起。你知道吗

相关问题 更多 >

    热门问题