我一直在尝试加密 PHP 5.2 中的某些内容,如下所示:
$key = "12345678901234567890123456789012345678901234567890123456";//56 chars
$iv = "12345678";//8 chars
$text = "Nick is pooping.";//16 chars
$enc = mcrypt_encrypt("blowfish", $key, $text, "cbc", $iv);
var_dump($enc); echo "<br>";
var_dump(base64_encode($enc)); echo "<br>";
这是输出:
string(16) "–±–%ê„zÆtȾ R"
string(24) "lrGWJeofhHrGdMi+BiBSHQ=="
我在我的 iOS 端使用这个,代码如下:
Blowfish* _blowfish = [BlowfishAlgorithm new];
[_blowfish setMode:[BlowfishAlorithm buildModeEnum:@"CBC"]];
[_blowfish setKey:@"12345678901234567890123456789012345678901234567890123456"];
[_blowfish setInitVector:@"12345678"];
[_blowfish setupKey];
NSLog(@"%@",[_blowfish encrypt:@"Nick is pooping."]);
这输出:
3132333435363738f61e0c4683e55fe061f1951e7a8182be
base64_encode 在 php 中不起作用,我不知道如何匹配它们以使它们输出相同。:(