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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:46:14+00:00 2026-06-14T23:46:14+00:00

There’s a mcrypt snippet on several webs: https://stackoverflow.com/a/11538728/408872 http://www.binrand.com/post/3810303-mcrypt-md5-how-to-create-an-online-encryption-decryption-web-page.html http://www.techbees.org/best-way-to-use-php-to-encrypt-and-decrypt/ $key = ‘password to

  • 0

There’s a mcrypt snippet on several webs:

https://stackoverflow.com/a/11538728/408872

http://www.binrand.com/post/3810303-mcrypt-md5-how-to-create-an-online-encryption-decryption-web-page.html

http://www.techbees.org/best-way-to-use-php-to-encrypt-and-decrypt/

$key = 'password to (en/de)crypt';
$string = ' string to be encrypted '; // note the spaces

$encrypted = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $string, MCRYPT_MODE_CBC, md5(md5($key))));
$decrypted = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($encrypted), MCRYPT_MODE_CBC, md5(md5($key))), "\0");

echo 'Encrypted:' . "\n";
var_dump($encrypted);

echo "\n";

echo 'Decrypted:' . "\n";
var_dump($decrypted); // spaces are preserved

Anybody knows why extra spaces are introduced on $string?

  • 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-14T23:46:15+00:00Added an answer on June 14, 2026 at 11:46 pm

    The sources you have provided all use nearly exactly the same code. I can only assume they stole the code from each other. So it’s not several sites doing this, it was most likely a single site, and the others who didn’t really understand what was going on simply inherited this.

    There is no good reason to add additional spaces to a string prior to encrypting it, it does not enhance the strength of the cryptography in any way, it doesn’t make it “better”.

    My guess would be that in these examples, it has been done to show that functions like trim do not affect the contents of an encrypted stream. (I personally don’t understand why this needs to be proved – it seems entirely logical to me)

    If you’re accepting a base64 encoded encrypted data (perhaps from a form submission), you will most likely trim the submitted data to remove any chaff the user left in there, I suspect someone somewhere was concerned that trimming the encrypted data would break the original plaintext.

    Edit:

    Note, if this string wasn’t base64 encoded, it would be entirely possible to damage the ciphertext. Since the ciphertext would be represented in binary form, it is possible that it would have whitespace characters at the end, which could be trimmed off causing corruption.

    Edit 2:

    md5(key) for the key, and md5(md5(key)) for the initialisation vector are both terrible terrible ways to implement this.

    Firstly, AES 256 should have a 256 bit key. If you want to use a passphrase, then use hash('sha256', $passphrase, true). The final true makes it return the result as binary, not hex encoded, and this is important so you actually get as much entropy as possible in your key.

    Secondly, initialisation vectors should not be re-used, ever. md5(md5(key)) will always produce the same value, for the same key. This weakens your encryption considerably if an attacker manages to obtain several ciphertexts.

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

Sidebar

Related Questions

There is some contradiction in the api documentation: on one location: https://developer.foursquare.com/docs/responses/user on another
There's a few previous questions on StackOverflow questioning how one goes about accessing local
There is a website called Gild.com that has different coding puzzles/challenges for users to
There are several shading languages available today like GLSL, HLSL, CG, which one to
There are 2 different article types: post(blog) and page in Octopress. What if I
I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
Let's say I'm outputting a post title and in our database, it's Hello Y’all
There are several generics libraries with numerous overlapping modules in just the Haskell Platform
There are several large C++ source files. We need to find all pointer arithmetic

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.