Op 18 okt. 2012 21:50 schreef "Rick Dwyer" <rpdwyer@xxxxxxxxxxxxx> het volgende: > > On Oct 18, 2012, at 2:38 PM, Matijn Woudt <tijnema@xxxxxxxxx> wrote: > > > On Thu, Oct 18, 2012 at 7:19 PM, Rick Dwyer <rpdwyer@xxxxxxxxxxxxx> wrote: > >> To correct what I posted below, $code that I'm passing to my function is encrypted… not plain text: > >> > >> ch7WvaSrCiHLstNeNUp5SkPfPgw0Z8vrNPJT+9vU7jN/C > >> > >> --Rick > >> > >> > >> On Oct 18, 2012, at 12:06 PM, Rick Dwyer <rpdwyer@xxxxxxxxxxxxx> wrote: > >> > >>> Hello all. > >>> > >>> Has anyone ever tried to decode a JAVA AES/CBC encrypted string with PHP before? > >>> > >>> I found a tutorial online with the following code to use as starting point, but it fails to return anything readable: > >>> > >>> $code ='Hello World'; > >>> $key = 'my key'; > >>> > >>> function decrypt($code, $key) { > >>> $key = hex2bin($key); > >>> $code = hex2bin($code); > >>> $td = mcrypt_module_open("rijndael-128", "", "cbc", ""); > >>> mcrypt_generic_init($td, $key, "fedcba9876543210"); > >>> $decrypted = mdecrypt_generic($td, $code); > >>> mcrypt_generic_deinit($td); > >>> mcrypt_module_close($td); > >>> return utf8_encode(trim($decrypted)); > >>> } > >>> > >>> > >>> function hex2bin($hexdata) { > >>> $bindata = ""; > >>> for ($i = 0; $i < strlen($hexdata); $i += 2) { > >>> $bindata .= chr(hexdec(substr($hexdata, $i, 2))); > >>> } > >>> return $bindata; > >>> } > >>> echo decrypt($code, $key); > >>> > >>> The above returns output containing a series of unprintable characters. > >>> > >>> I thought maybe it was due to $code not being in a hex format, but after converting to hex and resubmitting, I still unprintable characters. > >>> > >>> Any info is appreciated. > >>> > >>> --Rick > > > > > > Your key is not in hexadecimal, could it be Base64? > > I tried base64_decode($code) without luck as well. > > How about no conversion at all? Just use it as a plaintext key? Don't you have the java source that explains in what format the key is?