Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6853659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:32:18+00:00 2026-05-27T01:32:18+00:00

Seems that mcrypt_decrypt can’t proper decrypt my string (all works fine in var_dump except

  • 0

Seems that mcrypt_decrypt can’t proper decrypt my string (all works fine in var_dump except when decrypting – load_decrypted value is wrong). Any help would be appreciated.

array
  'salve_plain' => string 'a:1:{s:8:"modified";i:1321974656;}' (length=34)
  'save_encrypted' => string '^ånÄc¥JŸRæk®»}J%áR–y #‡nwZX\µÚ™È§œ‘5‚<_¹M¿ÔT9k)…ª  Ø' (length=64)
  'save_encoded' => string 'XuVuxGOlA0qfUuYXa667fUoSEyXhBVKWeSAjh253EFpYXLUS2pnIp5yRNa3LgjxfuRNNv9RUOe67qmsphaoJ2A==' (length=88)

array
  'load_undecoded' => string 'XuVuxGOlA0qfUuYXa667fUoSEyXhBVKWeSAjh253EFpYXLUS2pnIp5yRNa3LgjxfuRNNv9RUOe67qmsphaoJ2A==' (length=88)
  'load_decoded' => string '^ånÄc¥JŸRæk®»}J%áR–y #‡nwZX\µÚ™È§œ‘5‚<_¹M¿ÔT9k)…ª    Ø' (length=64)
  'load_decrypted' => string '-dœÞ{*€ ¥ûü(1À�ðú-›(!*»ÓÍW¦;}' (length=34)

PHP load() function:

private function load()
{

    // Decoding
    $plain = file_get_contents($this->filename);
    $decoded = base64_decode($plain);

    // Decrypting
    $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
    $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
    $decrypted = trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($this->secret),
        $decoded, MCRYPT_MODE_CBC, $iv));

    // Deserializing & loading
    $this->data = unserialize($decrypted);
    var_dump(array('load_undecoded' => $plain, 'load_decoded' => $decoded,
        'load_decrypted' => $decrypted));
}

PHP save() function:

private function save()
{

    // Serialization
    $serialized = serialize($this->data);

    // Encrypting
    $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
    $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
    $encrypted = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($this->secret),
        $serialized, MCRYPT_MODE_CBC, $iv);

    // Encoding & saving
    $encoded = base64_encode($encrypted);
    file_put_contents($this->filename, $encoded);

    var_dump(array('salve_plain' => $serialized,
        'save_encrypted' => $encrypted, 'save_encoded' => $encoded));

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:32:19+00:00Added an answer on May 27, 2026 at 1:32 am

    Unfortunately you need the same $iv in both the load and the save.

    // Creates a random value so that the same message encoded with the same key
    $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
    

    A way around it is to use

    $mode = MCRYPT_MODE_CFB;
    

    Encrypt with

    $encrypted = mcrypt_encrypt($cipher, $key, $iv . $message, $mode, $iv);
    

    Prefix the encoded message with the IV, and then in decoding use

    $decrypted = mcrypt_decrypt($cipher, $key, $encrypted, $mode, str_pad('', $iv_size));
    $decrypted = substr(rtrim($decrypted, "\0"), $iv_size);
    

    CFB has the ability to re-sync during decryption, and can use this ‘recovery’ feature to put your IV in.

    Also, depending on the number of IVs you’re creating, you may want to use urandom rather then random.

    $iv = mcrypt_create_iv($iv_size, MCRYPT_DEV_URANDOM);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It seems that anyone can snoop on incoming/outgoing .NET web service SOAP messages just
Seems,that very basic question. Anyway can't get the meaning of next definition from Spring
It seems that these can only be generated on Unix and then copied over
It seems that in Lua, I can either pass vararg on to another function,
Seems that when i create an object, the time is not correct. You can
It seems that clear: right causes also clear: left for all consecutive floats! See
Seems that lot of people already know that issue but I can not find
It seems that all roads lead to having to use PyISAPIe to get Django
Seems that iPad rules overwrite iPhone4 related rules. How can I solve this problem?
Seems that web.xml for a servlet has an element called <enabled>false</enabled> that can be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.