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);