Why do these weird characters appear in mcrypt?

I encrypt and decrypt successfully, but when I decrypt the value, "strange characters", "" appear at the end of the line. The starter $_POST['value']does not have a space or any strange character.

How can i solve this?

I am encrypting with this:

$key = 'my key';
$td = mcrypt_module_open('tripledes', '', 'ecb', '');
$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
mcrypt_generic_init($td, $key, $iv);        
$id = mcrypt_generic($td, $_POST['value']);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);

I will decrypt with this:

$key = 'my key';
$td = mcrypt_module_open('tripledes', '', 'ecb', '');
$iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
mcrypt_generic_init($td, $key, $iv);
$id = mdecrypt_generic($td, $_COOKIE['value']);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
+3
source share
5 answers

This is just adding a result based on the block size used. If you use rtrim (), you will get rid of them.

+6
source

These are unicode objects. Try utf8_decode () on the output.

There is also a related closed PHP error

mcrypt , iso-8859-1, utf-8 , , .

mcrypt.

En/Decrypt VB PHP VB PHP mcrypt

, , , VB9, UTF char, , 8- .

, 1234, chr (4) ( ) php use chr / . , php, , .

+3

cfb ecb, , IV . - IV ( , - "return $encrypted_data" , $iv. $Encrypted_data $encrypted_data IV substr()). .

+1

.

function pkcs5_unpad($text)
{
    $pad = ord($text{strlen($text)-1});
    if ($pad > strlen($text))
        return false;
    if (strspn($text, chr($pad), strlen($text) - $pad) != $pad)
        return false;
    return substr($text, 0, -1 * $pad);
}
0

Not VB PHP () PHP (), UTF-8, - UTF-8, - UTF-8.

Not- it's all. I encrypt two phrases. The former have strange characters, while the latter do not. All values ​​are POST from the same <form>.

-1
source

Source: https://habr.com/ru/post/1710975/


All Articles