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

  • Home
  • SEARCH
  • 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 3975504
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:41:35+00:00 2026-05-20T04:41:35+00:00

Does anyone know why this php encrypt/decrypt is not working? We used this in

  • 0

Does anyone know why this php encrypt/decrypt is not working?
We used this in our website, and it worked mostly. But now we made it a command line script, and it stopped working at all…

We tried encoding the key to utf8 and tried to remove the trim. But both are not working.

$e = new enc();
$pass = !isset($argv[1]) ? 'ill' : $argv[1];
$encPass = $e->_encrypt($pass);
$decPass = $e->_decrypt($encPass);

echo 'input: '. $pass . "\n";
echo 'encode: ' . $encPass . "\n";
echo 'decode: ' . $decPass;

class enc
{
/**
     * Encrypt data using AES256
     *
     * @param string $data The plaintext
     * @return string The encyrypted data
     */
    function _encrypt($data)
    {
        $ivSize = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
        $iv = mcrypt_create_iv($ivSize, MCRYPT_RAND);
        return mcrypt_encrypt(
            MCRYPT_RIJNDAEL_256, "gw2iYt26Gw", trim($data), MCRYPT_MODE_ECB,
            $iv
        );
    }

    /**
     * Decrypt data using AES256
     *
     * @param string $data The AES256 encrypted data
     * @return string The decyrypted data
     */
    function _decrypt($data)
    {
        $ivSize = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
        $iv = mcrypt_create_iv($ivSize, MCRYPT_RAND);
        return trim(
            mcrypt_decrypt(
                MCRYPT_RIJNDAEL_256, "gw2iYt26Gw", trim($data),
                MCRYPT_MODE_ECB, $iv
            )
        );
    }
}
?>

EDIT:
Little fix for using encPass to decrypt

  • 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-20T04:41:36+00:00Added an answer on May 20, 2026 at 4:41 am

    You’re decrypting the plain password.

    Do:

    $decPass = $e->_decrypt($encPass);
    

    EDIT after question update: You’ll have to remove the call to trim() when decoding. It messes up your input. Weed out the trimming in enc::_decrypt() and it works.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know what this means. Getting this in C# winforms applications: Not a
does anyone know how to make live javascript time running.. i have this php
Does anyone know what this value is for? If it is set to 1,
I cannot find this in the documentation anywhere. Does anyone know if this is
Does anyone know what is wrong with this query? SELECT DISTINCT c.CN as ClaimNumber,
Does anyone know how to turn this string: Smith, John R Into this string:
does anyone know if you can do something like this using the (N)Hibernate criteria
Does anyone know of crossbrowser equivalent of explicitOriginalTarget event parameter? This parameter is Mozilla
Does anyone know? And a bigger question is what happens when you encounter this
Does anyone know how to change the brush for a menu's background? This sounds

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.