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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:07:24+00:00 2026-06-08T15:07:24+00:00

A PHP application I’m maintaining uses Rijndael_256 with EBC_MODE encryption with mcrypt. Fun has

  • 0

A PHP application I’m maintaining uses Rijndael_256 with EBC_MODE encryption with mcrypt. Fun has it that the key isn’t 256 bits long, but only 160. According to the mcrypt_encrypt documentation the key is padded with \0 to get the required size if it’s too small.

The key with which the data will be encrypted. If it’s smaller than
the required keysize, it is padded with ‘\0’. It is better not to use
ASCII strings for keys.

This seem to happen at around the start of line 1186 in mcrypt.c and modifying the key at line 1213.

So lets say we’ve got $key = 'abcdefghijkm'; which is too short, but PHP’s implementation of mcrypt makes sure it’s extended to 32 characters (or 256 bit) when using RIJNDAEL_256. What will the final key look like?

I’m asking this because another application is being built that uses the same encrypted data, but is in another language. Perl to be exact and I’m using Crypto::Rijndael. For the given example key, what is the exact key I would have to feed to Crypto::Rijndael (or any other for that matter) to be able to decrypt the data again?

Update

With Perl I can generate a key that’s \0 padded doing pack('a32', 'my secret key'); (or Z32), length() will report 32 and the Crypt::Rijndael module accepts the key. Looking at the source of PHP’s mcrypt this should be the key that’s being generated (\0 padded), but it simply won’t take it.

In theory in PHP pack('a32', 'my secret key'); should result in the same \0 padded key that PHP’s mcrypt generates, but this isn’t the case.

I’m very close to just encrypt everything again but with a new key. This is taking too much time.

  • 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-08T15:07:25+00:00Added an answer on June 8, 2026 at 3:07 pm

    The issue isn’t the key’s padding, it’s that you’re using two different block sizes. In PHP, using MCRYPT_RIJNDAEL_256 uses a block size of… 256 bits. However, in perl using Crypt::Rijndael, they note:

    blocksize
    The blocksize for Rijndael is 16 bytes (128 bits), although the algorithm actually supports any blocksize that is any multiple of our bytes. 128 bits, is however, the AES-specified block size, so this is all we support.

    So there’s no key that will allow for conversion between those different algorithms. You can either switch to 128 bits in PHP:

    <?
    $key = "abcdefghijklmnopqrstuvwxyz";
    $data = "Meet me at 11 o'clock behind the monument.";
    $crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $data, MCRYPT_MODE_ECB, nil);
    echo bin2hex($crypttext) . "\n";
    // prints c613d1804f52f535cb4740242270b1bcbf85151ce4c874848fd1fc2add06e0cc2d26b6403feef4a8df18f7dd7f8ac67d
    ?>
    

    Which Perl can decrypt without a problem using Crypt::Rijndael:

    use Crypt::Rijndael;
    $key = "abcdefghijklmnopqrstuvwxyz\0\0\0\0\0\0";
    $crypttext = "c613d1804f52f535cb4740242270b1bcbf85151ce4c874848fd1fc2add06e0cc2d26b6403feef4a8df18f7dd7f8ac67d";
    $cipher = Crypt::Rijndael->new($key, Crypt::Rijndael::MODE_ECB());
    print $cipher->decrypt(pack('H*', $crypttext));
    # prints "Meet me at 11 o'clock behind the monument."
    

    Or you can switch to a different Perl module that supports more block sizes, e.g., Crypt::Rijndael_PP:

    # Same PHP code except using MCRYPT_RIJNDAEL_256
    # prints f38469ec9deaadbbf49bb25fd7fc8b76462ebfbcf149a667306c8d1c033232322ee5b83fa87d49e4e927437647dbf7193e6d734242d583157b492347a2b1514c
    

    Perl:

    use Crypt::Rijndael_PP ':all';
    $key = "abcdefghijklmnopqrstuvwxyz\0\0\0\0\0\0";
    $crypttext = "f38469ec9deaadbbf49bb25fd7fc8b76462ebfbcf149a667306c8d1c033232322ee5b83fa87d49e4e927437647dbf7193e6d734242d583157b492347a2b1514c";
    print rijndael_decrypt(unpack('H*', $key), MODE_ECB, pack('H*', $crypttext), 256, 256);
    # prints "Meet me at 11 o'clock behind the monument."
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a php application that uses the google feed api to get the
I have a legacy PHP application that uses the following URL structure /product_info.php?products_id=YYY where
I'm developing a PHP application that uses FFMPEG-PHP to split videos and convert them
I am building a PHP application that uses a select menu to build email
I have a PHP application that has grown in size. The database used to
I wrote a small PHP application several months ago that uses the WordPress XMLRPC
I have a PHP application that has passwords stored in the database as the
I have a PHP application that I have been having some problems with, some
I'm writing a PHP application which uses AJAX to submit forms via POST when
I have a php application that saves the pictures on the server and also

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.