php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67287 Warning: mcrypt_encrypt(): Only keys of size 24 supported
Submitted: 2014-05-15 14:50 UTC Modified: 2014-05-15 16:37 UTC
From: mengxiangbaidu at qq dot com Assigned:
Status: Duplicate Package: mcrypt related
PHP Version: 5.6.0beta2 OS: windows
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: mengxiangbaidu at qq dot com
New email:
PHP Version: OS:

 

 [2014-05-15 14:50 UTC] mengxiangbaidu at qq dot com
Description:
------------
php version <= 5.5.12

string(6) "zxcvbn"

Warning: mcrypt_encrypt(): Key of size 32 not supported by this algorithm.  in /test.php on line 9

Warning: mcrypt_decrypt(): Key of size 32 not supported by this algorithm.  in /test.php on line 17
string(0) "zxcvbn"


php version >= 5.6

string(6) "zxcvbn"

Warning: mcrypt_encrypt(): Key of size 32 not supported by this algorithm. Only keys of size 24 supported in /test.php on line 9

Warning: mcrypt_decrypt(): Key of size 32 not supported by this algorithm. Only keys of size 24 supported in /test.php on line 17
string(0) ""

================

I know this warning is good thing 。  If you are upgrading php 5.5 to 5.6 ,   the php program does not work 。This maybe a serious problem。




Test script:
---------------
<?php
function encrypt($data, $key) {

    $block = mcrypt_get_block_size(MCRYPT_TRIPLEDES, MCRYPT_MODE_ECB);
    $pad = $block - (strlen($data) % $block);
    $data .= str_repeat(chr($pad), $pad);

    $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_TRIPLEDES, MCRYPT_MODE_ECB), MCRYPT_RAND);
    $encrypted = mcrypt_encrypt(MCRYPT_TRIPLEDES, $key, $data, MCRYPT_MODE_ECB, $iv);

    return $encrypted;
}

function decrypt($data, $key) {

    $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_TRIPLEDES, MCRYPT_MODE_ECB), MCRYPT_RAND);
    $data = mcrypt_decrypt(MCRYPT_TRIPLEDES, $key, $data, MCRYPT_MODE_ECB, $iv);

    $block = mcrypt_get_block_size(MCRYPT_TRIPLEDES, MCRYPT_MODE_ECB);
    $pad = ord($data[($len = strlen($data)) - 1]);
    $decrypted = substr($data, 0, strlen($data) - $pad);

    return rtrim($decrypted);
}
$key = md5('asdfgh');
$original_data = 'zxcvbn';
var_dump($original_data);
$data = encrypt($original_data, $key);
$data = base64_encode($data);
$data = base64_decode($data);
$data = decrypt($data, $key);
var_dump($data);

Expected result:
----------------
string(6) "zxcvbn"

Warning: mcrypt_encrypt(): Key of size 32 not supported by this algorithm. Only keys of size 24 supported in /test.php on line 9

Warning: mcrypt_decrypt(): Key of size 32 not supported by this algorithm. Only keys of size 24 supported in /test.php on line 17
string(0) "zxcvbn"

Actual result:
--------------
string(6) "zxcvbn"

Warning: mcrypt_encrypt(): Key of size 32 not supported by this algorithm. Only keys of size 24 supported in /test.php on line 9

Warning: mcrypt_decrypt(): Key of size 32 not supported by this algorithm. Only keys of size 24 supported in /test.php on line 17
string(0) ""



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-05-15 16:37 UTC] levim@php.net
-Status: Open +Status: Duplicate
 [2014-05-15 16:37 UTC] levim@php.net
Seems to have double-posted.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Dec 11 22:01:27 2024 UTC