0
我正在用PHP改写Perl Web应用程序,但是我遇到的问题是MySQL数据库中的一些数据使用Perl中的Blowfish_PP/CBC加密。我似乎无法在PHP中找到它的实现,所以我开始重新编写一些PHP代码。使用Crypt :: CBC和Blowfish_PP与PHP
我越来越接近,但在正则表达式转换上遇到了一些麻烦。即:
my ($salt) = $$input_stream =~ /^Salted__(.{8})/s;
其中$ INPUT_STREAM是被解压缩后的加密数据:
Salted__�/kW��t�}��`�
我不知道如何用PHP编写该正则表达式,所以任何帮助,将不胜感激。如果任何人有任何其他想法,我还包括我在PHP下面使用的完整代码。它还没有完成,因为我被困在上面的正则表达式中。
$pass = "VGhlIHRhZHBvbGUgc251ZmZzIGEgY2FuZGxlLiBUaGUgZ29sZGZpc2ggaG93bHMgYXQgbWlkbmlnaHQu";
$pass = base64_decode($pass);
$ciphertext = "53616c7465645f5fff2f6b57dcf974857dd7e5010b60eea";
$ciphertext = pack('H*',$ciphertext);
// Here's what I did with the regex, but pretty sure this is wrong.
$c2 = preg_split('/^Salted__(.{8})/s',$ciphertext);
$salt = $c2[1];
$ciphertext = substr($ciphertext,16,strlen($ciphertext));
$desired_len = 64; (should be keylen + ivlen, but this works)
$data = "";
$d = '';
while (strlen($data) < $desired_len) {
$d = md5($d . $pass . $salt);
$data .= $d;
}
$key = substr($data,0,56);
$iv = substr($data,56,8);