encryption - PHP Decrypting AES returns padding at front of string? -



encryption - PHP Decrypting AES returns padding at front of string? -

i've been wrestling decrypting given string, generated remote coldfusion server, in php using aes in cbc mode pkcs5 padding. i've gotten point can decrypt string almost perfectly, issue there appears cruft @ origin of string. thought padding happened @ end, looking @ decrypted string, there's nil @ end, origin padded out string 64 characters long (the original string 32 characters long.) attempted switch padding removal code @ origin instead of end, characters don't provide info can utilize decipher how much padding remove, think coming somewhere else. here's code far

function decrypt($hash) { $enc_key = "oq2vh+gswpn2crpccodtkg=="; $cipher = "rijndael-128"; $str = mcrypt_decrypt($cipher, base64_decode($enc_key), base64_decode($hash), mcrypt_mode_cbc); $block = mcrypt_get_block_size(mcrypt_rijndael_128, mcrypt_mode_cbc); $pad = ord($str[($len = strlen($str)) - 1]); $len = strlen($str); $decrypted = substr($str, 0, strlen($str) - $pad); if($decrypted != null) { $params = explode ('|', $decrypted); } homecoming (object)array( 'input' => $hash, 'pad' => $pad, 'len' => $len, 'blocksize' => $block, 'aes_key' => $enc_key, 'cipher' => $cipher, 'result' => $params, 'decrypted' => $decrypted, 'padded' => $str );

if encrypt string (using coldfusion, '"aes/cbc/pkcs5padding"' algorithm , base64 encoding):

"test@example.com|test|1400863515"

i encrypted string:

qro04vmtw76qvl0hscmyz/sfgnv/8d88h9kt60ja5ijdg/kmt7udrn2izuqzkopvljxoc4novztmgsk0cmxjvg==

and when run through above php function, output:

¹¾sò'->äe¿fÏäj±test@example.com|test|1400863515

what characters @ beginning? why there no padding @ end? i've read through dozens of posts on , elsewhere (which how got far) lastly piece has me scratching head.

(from comments ...)

cbc mode requires iv. "decrypting wrong iv causes first block of plaintext corrupt ...". seek using same iv on both sides

php encryption coldfusion aes pkcs#5

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -