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 8521581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:52:06+00:00 2026-06-11T06:52:06+00:00

I am trying to encrypt some data in PHP using the Rijndael cipher in

  • 0

I am trying to encrypt some data in PHP using the Rijndael cipher in CBC mode with a 256bit key but for some reason I get the following error message:

mcrypt_encrypt() Module initialization failed

My code:

    $hashKey = hash('sha256',$key);
    $iv = hash('sha256',$hashKey);

    //                                                 ------Cipher-------------key-------------Data-------------Mode---------IV--
    $encryptedQuestion = base64_encode(mcrypt_encrypt('MCRYPT_RIJNDAEL_256', $hashKey , $_POST['question'], MCRYPT_MODE_CBC, $iv));

Can anyone see whats wrong with this?

  • 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-06-11T06:52:08+00:00Added an answer on June 11, 2026 at 6:52 am

    There are a few issues with the code that I can spot:

    1. Your $iv should not be dependent on $hashKey; rather, you should create it separately using mcrypt_create_iv().

    2. Your $hashKey should be binary rather than textual.

    3. MCRYPT_RIJNDAEL_256 is a constant, it should not be passed as a string.

    The following code is more verbose than yours, but it should give you an insight in the steps required to encrypt something:

    $crypto = mcrypt_module_open(MCRYPT_RIJNDAEL_256, '', MCRYPT_MODE_CBC, '');
    $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($crypto), MCRYPT_DEV_URANDOM);
    
    $hkey = hash('sha256', $key, true);
    
    mcrypt_generic_init($handle, $hkey, $iv);
    
    $enc_question = mcrypt_generic($handle, $_POST['question']);
    
    mcrypt_generic_deinit($handle);
    mcrypt_module_close($handle);
    

    I’ve also left out any error checks.

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

Sidebar

Related Questions

I'm trying to use PHP and OpenSSL to encrypt some data using a public
In a Rails 3.0 (Ruby 1.9.2) app I'm trying to encrypt some data using
I am trying to encrypt and decrypt some simple text. But for some reason
I am trying to encrypt some plain text with a public key using RSA_public_encrypt(),
I'm trying to encrypt some binary data in Java with a public key as
I'm trying to encrypt some date using a public key derived form the exchange
I am trying to encrypt some data with the following code: public static byte[]
I'm trying to measure how long it takes read then encrypt some data (independently).
I'm trying to encrypt some content with an RSA private key. I'm following this
I'm trying to encrypt an array of 256 bytes by using RSACryptoServiceProvider but I'm

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.