|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-06-30 05:15 UTC] johanna at neiatec dot com
[2009-06-30 08:41 UTC] derick@php.net
[2009-06-30 14:00 UTC] guljo at hotmail dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 17:00:02 2025 UTC |
Description: ------------ RIJNDAEL_256 with ECB_MODE does not work everytime properly, here is the example of a string that is encrypted and then cannot get decrypted to the original. Reproduce code: --------------- $string = "numero_documento_funcionario:=:31194443#&#seccional:=:Principal#&#correo_funcionario:=:cinterno@tulua.gov.co#&#fecha_solicitud:=:2009-04-30 00:00:00#&#numero_radicacion:=:000001#&#numero_camara:=:36###198"; echo "To encrypt: <br /><br />\n"; $key = "9c08eb33218aa11eb8f1423f85d5f554"; echo $string."<br /><br />\nEncrypted: <br /><br />\n"; $encrypted = cifrar($string, $key); echo $encrypted."<br /><br />\nDecrypted ??: <br /><br />\n"; echo descifrar($encrypted, $key)."<br /><br /><br /><br />\n"; function cifrar($message, $key){ $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB); $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); $enc=mcrypt_encrypt(MCRYPT_RIJNDAEL_128,$key, $message, MCRYPT_MODE_ECB, $iv); $enc = base64_encode(trim($enc)); return $enc; } function descifrar($enc, $key){ $enc = base64_decode(trim($enc)); $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB); $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $enc, MCRYPT_MODE_ECB, $iv)); } Expected result: ---------------- I expect the decrypted string to be just the same as the original string. Actual result: -------------- The last characters are not decrypted properly. And this just happens with this very string, if you change any character, add or take away any character, it works. But it is a flaw as strings as this one are generated by my application and it fails at times.