#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    30
    Rep Power
    1

    Mcrypt_decrypt giving me strange output


    Guys ,

    I am trying to decrypt a encrypted/encoded string using AES 128 /CBC algorithm. I am creating the MD5 hash for generating the key and then using mcrypt_decrypt to get the decrypted string.

    I am not getting the correct output. This is what i am trying to do
    #########################

    $str = '............KNqMcewHI=';
    $result = md5($str);
    $data = '................BSycdvBClO7Wr29Jp4AktNN14d87wQ+HpTv9wvKuVC.....KkEO4';
    $decode = base64_decode($data);

    $data1 = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $result, $decode, MCRYPT_MODE_CBC,' ');

    echo $data1;

    ############################

    i am getting following

    .A?A3efYOJ"/'ɢ

    While I was expecting readable text .. can anybody help me here and point if i am doing everything correctly or i need to do some thing else.

    Thanks a lot
    Amit
    Last edited by requinix; August 7th, 2013 at 02:37 PM. Reason: substituting harmless example data (in blue)
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,007
    Rep Power
    9398
    Looks like your $data might be corrupted a bit. I get output ending with "_support". By the way, that looks like important information so I'm going to edit into your post something harmless instead.

    1. The key is supposed to be binary bytes. md5() by default returns a hex string.
    PHP Code:
    $result md5($strtrue); 
    2. CBC needs an IV. If you don't have one then provide \0s. Your cipher is 128 bits so that's 16 \0s.
    PHP Code:
    $data1 mcrypt_decrypt(MCRYPT_RIJNDAEL_128$result$decodeMCRYPT_MODE_CBC"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"); 
    Last edited by requinix; August 7th, 2013 at 02:42 PM.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    30
    Rep Power
    1
    Originally Posted by requinix
    Looks like your $data might be corrupted a bit. I get output ending with "_support". By the way, that looks like important information so I'm going to edit into your post something harmless instead.

    1. The key is supposed to be binary bytes. md5() by default returns a hex string.
    PHP Code:
    $result md5($strtrue); 
    2. CBC needs an IV. If you don't have one then provide \0s. Your cipher is 128 bits so that's 16 \0s.
    PHP Code:
    $data1 mcrypt_decrypt(MCRYPT_RIJNDAEL_128$result$decodeMCRYPT_MODE_CBC"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"); 
    Awesome requnix .. yeah passing "true" to md5 made a difference , I got required data.. i know i have some junk in start but i can rip that off.. Thanks a lot again

IMN logo majestic logo threadwatch logo seochat tools logo