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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:42:01+00:00 2026-06-09T03:42:01+00:00

I am having some odd issues here…. I have the two following scripts: First,

  • 0

I am having some odd issues here….

I have the two following scripts:

First, a PHP script (which I am using http://writecodeonline.com/php/ to test)

$key = '[E%Xr6pG-IDIA89_&=NI[AREofOy0#Mv[nJ7rO@T^PwgT!NVY*Hri@($p4luBM)ugVvbnAnWL@xGK*jBP3s$g#-XTH{e3@X*0StJ';
$string = 'Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing ';

//
$encrypted = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, md5($key), $string, MCRYPT_MODE_ECB));

$decrypted = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_128, md5($key), base64_decode($encrypted), MCRYPT_MODE_ECB), "\0");


echo $encrypted . "<br>";
echo $decrypted;

Second, a Java class,

import java.io.*;
import java.net.*;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

import javax.crypto.*;
import javax.crypto.spec.*;

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.digest.DigestUtils;


public class Main {

    /**
     * @param args
     * @throws Exception 
     */
    public static void main(String[] args) throws Exception {

        String pw = "[E%Xr6pG-IDIA89_&=NI[AREofOy0#Mv[nJ7rO@T^PwgT!NVY*Hri@($p4luBM)ugVvbnAnWL@xGK*jBP3s$g#-XTH{e3@X*0StJ";
        String str = encode("Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing ", pw);
        System.out.println(str);
        System.out.println(decode(str, pw));
    }

    public static String encode(String s, String p) throws Exception
    {
        String cleartext = padRight(s, s.length()+(16-(s.length()%16)));
        String key = DigestUtils.md5Hex(p);
        SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes(), "AES");
        Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding");
        cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
        byte[] encrypted = cipher.doFinal(cleartext.getBytes());
        return Base64.encodeBase64String(encrypted);
    }

    public static String decode(String encrypted, String p) throws Exception
    {
        byte[] bts = Base64.decodeBase64(encrypted);


        String key = DigestUtils.md5Hex(p);
        SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes(), "AES");
        Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding");
        cipher.init(Cipher.DECRYPT_MODE, skeySpec);



        byte[] decrypted = cipher.doFinal(bts);

        return new String(decrypted).replaceAll("\0", "");
    }

    public static String padRight(String s, int n) {
        while (s.length() < n)
        {
            s+="\0";
        }
        return s;
    }

}

Something very strange happens. When I test the PHP script, I get:

/wyCRFRmXFDGk0O5+EAHWv8MgkRUZlxQxpNDufhAB1r/DIJEVGZcUMaTQ7n4QAda/wyCRFRmXFDGk0O5+EAHWv8MgkRUZlxQxpNDufhAB1r/DIJEVGZcUMaTQ7n4QAda/wyCRFRmXFDGk0O5+EAHWv8MgkRUZlxQxpNDufhAB1r/DIJEVGZcUMaTQ7n4QAda/wyCRFRmXFDGk0O5+EAHWg==

as the encrypted code.

When I test the java code, however, I get:

/wyCRFRmXFDGk0O5+EAHWv8MgkRUZlxQxpNDufhAB1r/DIJEVGZcUMaTQ7n4QAda/wyCRFRmXFDGk0O5+EAHWv8MgkRUZlxQxpNDufhAB1r/DIJEVGZcUMaTQ7n4QAda/wyCRFRmXFDGk0O5+EAHWv8MgkRUZlxQxpNDufhAB1r/DIJEVGZcUMaTQ7n4QAda/wyCRFRmXFDGk0O5+EAHWsdyQJ3DP2jBsJcLh2n2wv0=

If you look closely, you will see that (somehow) the java text is longer! But, oddly, both of the texts are exactly the same up until “+EAH” which is when they diverge. I find this completely strange — why?

Because I have tested this code on numerous other strings, from lorum ipsum, to the word “Testing” with no errors. The only way I have found of causing this (so far) is to repeat a shortish word many times separated by spaces.

I am incredibly worried about this because I have no idea what other ways there are to trigger this strange behavior. So that leads me to my question… WHat in the name of davy jone’s locker is casking 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-09T03:42:03+00:00Added an answer on June 9, 2026 at 3:42 am

    I’m not an expert of encryption, but it may be a padding issue. You may try with the following.

    PHP
    Set the padding as follows:

    $blockSize = mcrypt_get_block_size(MCRYPT RIJNDAEIL_128, MCRYPT_MODE_ECB);
    $padding = $blockSize - (strlen($string) % $blockSize);
    $string .= str_repeat(chr($padding), $padding);
    

    This will use PKCS#5 padding, instead of PHP’s null padding.

    Java
    Change the following line:

    Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding");
    

    to:

    Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
    

    Unfortunately I don’t have an environment with Java where I can compare the results, but I hope it helps.

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

Sidebar

Related Questions

I'm having an odd issue in FF10 using jQuery 1.7.1. I have a gallery
I have audio constantly playing during my application. I am having some odd behavior
I'm having a particularly odd issue when developing Chrome extensions using jQuery. I have
I'm having some odd and intermittent errors, which I assume are related to my
I am having some issues implementing RestKit/CoreData with my application. Using the RKTwitterCoreData example
I'm having an odd issue. I have a simple web page, and for some
Having some odd issues with paperclip, s3 and imagemagick. The normal sized image will
My Java application is displaying some odd behaviour, and I'm having trouble finding a
I am having an odd error with Thread.sleep() on Java. For some reason, when
Having some trouble with R's garbage collection, when passing objects to C++. We have

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.