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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:34:57+00:00 2026-06-09T10:34:57+00:00

I am new to encryption. I want to encode a string with AES 128bit

  • 0

I am new to encryption. I want to encode a string with AES 128bit encryption. I can do this in PHP:

$key = 'Hello';
$plain = 'Hello Hello Hello Hello';

$cipher = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $plain, MCRYPT_MODE_CBC);

echo base64_encode($cipher);

This outputs:

bzXdTNochlsQwpR9hzSSS6ihG+MYIZIDZZlF85pIXlQ=

I tried the same with openssl command line:

openssl enc -aes-128-cbc -a -nosalt -in plain.txt -out encrypted.enc -pass pass:Hello

And the string saved in encrypted.enc is:

5apwiN8MdAuJ9nEW82XMyR0H3VKpI/vWc7xV2iVjCTE=

Why is it different?

The reason why I am trying to get the same output with both PHP and command line openssl is because I will have two separate web services communicating together. One service will have PHP available so I can use that but the other one will not be using PHP so I will probably have to use openssl in command line.

  • 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-09T10:35:00+00:00Added an answer on June 9, 2026 at 10:35 am

    You mixed up password and key. Add a -p to your openssl command line to see the actual key used and observe http://php.net/manual/en/function.mcrypt-encrypt.php string mcrypt_encrypt ( string $cipher , string $key <= key! Not password.

    Edit:

    You also have problems with padding. Now making your plain text 48 chars (3*128 bit=3*16 bytes) long:

    $plain = 'Hello Hello Hello Hellox';
    $plain .= $plain;
    function hexstr($hexstr) {
      // return pack('H*', $hexstr); also works but it's much harder to understand.
      $return = '';
      for ($i = 0; $i < strlen($hexstr); $i+=2) {
        $return .= chr(hexdec($hexstr[$i] . $hexstr[$i+1]));
      }
      return $return;
    }
    $cipher = @mcrypt_encrypt(MCRYPT_RIJNDAEL_128, hexstr('25c506a9e4a0b3100d2d86b49b83cf9a'), $plain, MCRYPT_MODE_CBC, hexstr('00000000000000000000000000000000'));
    
    echo base64_encode($cipher);
    echo "\n";
    

    And

    openssl enc -aes-128-cbc -a -iv 0  -nosalt -in plain.txt  -K 25c506a9e4a0b3100d2d86b49b83cf9a -nopad
    

    results the same:

    EZjBup0sfRAkIZ2/IQ3bKHWXHG4qBVv4uyW0PnxJJWvWHanNgE1QyBHMpWoZqejR
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to encrypt and decrypt a string this way Encryption string ----> convert
New to PHP and MySQL, have heard amazing things about this website from Leo
New to Regex. I want to validate to this format: Any character allowed, except
I'm new to this encryption thing, so i'm not realy sure how to format
I'm new to encryption and android and so asking this question. How does the
i am new to iPhone. i want to know which Encryption /decryption algorithm is
I need to store sensitive information (a symmetric encryption key that I want to
I'm new to PHP, I started about 3 weeks ago. I have a string,
I am using C# 4.0 Windows Application.I want to give encryption key to protect
How can I do AES 256 encryption in Blackberry... I am using for encryption

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.