简体   繁体   English

mcrypt_encrypt在php和ios中的不同结果

[英]mcrypt_encrypt different result in php and ios

I've been trying to encrypt something in PHP 5.2 like so: 我一直在尝试对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>";

This is the output: 这是输出:

string(16) "–±–%ê„zÆtȾ R" 
string(24) "lrGWJeofhHrGdMi+BiBSHQ==" 

I'm using this on my iOS side, with this code: 我用对我的iOS侧,使用此代码:

Blowfish* _blowfish = [BlowfishAlgorithm new];
[_blowfish setMode:[BlowfishAlorithm buildModeEnum:@"CBC"]];
[_blowfish setKey:@"12345678901234567890123456789012345678901234567890123456"];
[_blowfish setInitVector:@"12345678"];
[_blowfish setupKey];
NSLog(@"%@",[_blowfish encrypt:@"Nick is pooping."]);

This outputs: 输出:

3132333435363738f61e0c4683e55fe061f1951e7a8182be

base64_encode doesn't do the trick in php, and I can't figure out how to match them so that they output the same. base64_encode在php中无法解决问题,而且我不知道如何匹配它们,以便它们输出相同的结果。 :( :(

To remove these null characters, you can use the rtrim function. 要删除这些空字符,可以使用rtrim函数。 After running the decrypted output through that it should be equal. 在运行解密后的输出之后,它应该相等。

Please refer to this link for more information: 请参考此链接以获取更多信息:

https://stackoverflow.com/a/15352155/516512 https://stackoverflow.com/a/15352155/516512

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM