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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:29:03+00:00 2026-05-30T09:29:03+00:00

I had an implementation that encrypts an input string using mcrypt. Unfortunately I can’t

  • 0

I had an implementation that encrypts an input string using mcrypt. Unfortunately I can’t use this anymore because mcrypt isn’t installed on the server and I can’t install it.
So I’ve had a look at phpseclib but unfortunately I don’t get the same encrypted string. Here is my code:

include('Crypt/AES.php');

$key256 = "1234567890123456";
$iv =  "6543210987654321";

$cleartext = "This a teststring :)";

echo $cleartext . "<br /><br />";

$cipher = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');

if (mcrypt_generic_init($cipher, $key256, $iv) != -1)
{
  // PHP pads with NULL bytes if $cleartext is not a multiple of the block size..
  $cipherText = mcrypt_generic($cipher,$cleartext );
  mcrypt_generic_deinit($cipher);
}

$enc64 = bin2hex($cipherText);
echo $enc64 . "<br />";

while (strlen($cleartext) % 16 != 0) {
  $cleartext .= "\0";
}

$aes = new Crypt_AES();
$aes->setKey($key256);
$aes->setIV($iv);
$cipherText = $aes->encrypt($cleartext);
$enc64 = bin2hex($cipherText);
echo $enc64;

After running the script (on the development server that has mcrypt installed) I get the following output:

This a teststring 🙂

0fc60e5a06eca68d4aada496e0e83ea65806abfe7d8f72723da470e6c9e86372
0fc60e5a06eca68d4aada496e0e83ea65806abfe7d8f72723da470e6c9e8637231b74e99d9b729813e974f211550d175

As you can see both encrypted strings are identical. Almost. The one that has been encrypted with phpseclib is one block too long and I have no idea why. I’ve already tried different key and block sizes. I’ve also tried to use the Crypt_Rijndael class of phpseclib. Hope one of you can point me in the right direction.

  • 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-30T09:29:04+00:00Added an answer on May 30, 2026 at 9:29 am

    Copied comment: Have you checked that you are using the same padding in both versions.

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

Sidebar

Related Questions

I've read somewhere that the trunk version of Firefox already had a WebSocket implementation.
Had a good search here but can't see anything that gets my mind in
So I discovered that gcc already had a working implementation of std::atomic so I
I just had a look at Firemonkey's grid implementation and it turns out that
I have a class that contains a list of objects. I previously had this
I worked for a company that had both Java and .NET implementations of an
Had a coworker ask me this, and in my brain befuddled state I didn't
Had a page that was working fine. Only change I made was to add
I had a discussion with some colleagues mentioning that there are not too many
I wrote a linked list implementation for my java class earlier this year. This

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.