【发布时间】:2020-11-24 10:40:48
【问题描述】:
我有一个旧数据库,其内容是使用 DES 使用 mcrypt 加密的(是的,我知道,那是很久以前的事了) 加密方式是这样的:
/**
* General encryption routine for generating a reversible ciphertext
* @param String $string the plain text to encrypt
* @param String $key the encryption key to use
* @return String the cypher text result
*/
function encrypt($string, $key)
{
srand((double) microtime() * 1000000);
/* Open module, and create IV */
$td = mcrypt_module_open('des', '', 'cfb', '');
$ksub = substr(md5($key), 0, mcrypt_enc_get_key_size($td));
$iv_size = mcrypt_enc_get_iv_size($td);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
/* Initialize encryption handle */
if (mcrypt_generic_init($td, $ksub, $iv) != -1)
{
/* Encrypt data */
$ctxt = mcrypt_generic($td, $string);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
$ctxt = $iv . $ctxt;
return base64_encode($ctxt);
} //end if
}
而解密方法是这样的:
/**
* General decryption routine for recovering a plaintext
* @param String $string the cypher text to decrypt
* @param String $key the encryption key to use
* @return String the plain text result
*/
function decrypt($string, $key)
{
$ptxt = base64_decode($string);
/* Open module, and create IV */
$td = mcrypt_module_open('des', '', 'cfb', '');
$ksub = substr(md5($key), 0, mcrypt_enc_get_key_size($td));
$iv_size = mcrypt_enc_get_iv_size($td);
$iv = substr($ptxt, 0, $iv_size);
$ptxtsub = substr($ptxt, $iv_size);
/* Initialize encryption handle */
if (mcrypt_generic_init($td, $ksub, $iv) != -1)
{
/* Encrypt data */
$ctxt = mdecrypt_generic($td, $ptxtsub);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
return $ctxt;
} //end if
}
我需要在 PHP7.4 环境中提取这些数据,即使只是用更好的东西重新加密它,但我不确定如何使用 PHP7.4 中存在的东西(如钠)重现 mcrypt 操作. 我想一种方法是启动某种仍然具有 mcrypt 的遗留 PHP 安装并离线执行,但是有没有更直接的方式来编码解密方法?
【问题讨论】:
-
您能否添加一个示例加密数据,它是未加密的值,以及您问题的关键?
-
事实证明,我被告知的数据不是用 mcrypt 编码的。看起来条目都是 MD5 哈希,所以即使我可以让 mcrypt 工作,也不会很容易解密!
标签: php encryption