将Mcrypt RC4转换为PHP-OpenSSL

时间:2017-05-16 18:41:30

标签: php encryption php-7 mcrypt php-openssl

我将服务器从php 5更新为php 7,现在不推荐使用mcrypt函数。

我有以下代码:

$encryptedUserInfo = @mcrypt_encrypt(MCRYPT_ARCFOUR, $sessionKey, $json, MCRYPT_MODE_STREAM);

在stackoverflow中阅读一些帖子我找到了这段代码:

$message_padded = $message;
if (strlen($message_padded) % 8) {
    $message_padded = str_pad($message_padded,
        strlen($message_padded) + 8 - strlen($message_padded) % 8, "\0");
}

$encrypted_mcrypt = @mcrypt_encrypt(MCRYPT_ARCFOUR, $key, $message, MCRYPT_MODE_STREAM);
$encrypted_openssl = openssl_encrypt($message_padded, "RC4", $key, OPENSSL_RAW_DATA | OPENSSL_NO_PADDING);

printf("%s => %s\n", bin2hex($message), bin2hex($encrypted_mcrypt));
printf("%s => %s\n", bin2hex($message_padded), bin2hex($encrypted_openssl));

但我还是收到了不同的答案:

对于mcrypt:

7b22757365724e616d65223a6e756c6c2c2261747472696275746573223a7b227573657250726f6772616d73223a2250726f6772616d4e616d65227d7d => f373453d449b731f75d9a35dee7486d8c904465bfdf6e912eceb272f5dd8ee85fabde5ad06e3d87192e0fa90182c8bc4b096ad89866b643305b3f15eb0 

对于openssl:

7b22757365724e616d65223a6e756c6c2c2261747472696275746573223a7b227573657250726f6772616d73223a2250726f6772616d4e616d65227d7d000000 => 272b1b4c0a19e79e7234e8fb494cb162c6c551ec35352fc04bff3885ce34c211080d0cfaf70635cec929236b5f444a6916c529bb3a62db01fef8d0cb8dd2f3a1

所以,我认为不同的是在MCRYPT_MODE_STREAM,我不知道如何在openssl中做到这一点。

有人能帮助我吗? 谢谢!

1 个答案:

答案 0 :(得分:1)

我找到了解决方案......使用的方法不是RC4,是RC4-40

.nav > ul li {
text-align: center;
display: inline-block;
padding: 5px;

无需填充消息。