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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:10:33+00:00 2026-05-24T23:10:33+00:00

I have a blowfish encryption script in PHP and JAVA vice versa that was

  • 0

I have a blowfish encryption script in PHP and JAVA vice versa that was working fine until today when I came across a problem.

The same content is encrypted differently in Java vs PHP by only 2 chars, which is really weird.

PHP

wTHzxfxLHdMm/JMFnoh0hciS/JADvFFg

Java

wTHzxfxLHdMm/JMFnoh0hciS/D8DvFFg
-------------------------^^

As you see those two positions do not match. Unfortunately the value is a real email address and I can’t share it. Also I was not able to reproduce the problem with other few values I’ve tested. I’ve tried changing Base64 encode classes on Java, and that neither helped.

The source code for PHP is here, and for Java is here.

What could I do to resolve this problem?

  • 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-24T23:10:34+00:00Added an answer on May 24, 2026 at 11:10 pm

    Let’s have a look at your Java code:

    String c = new String(Test.encrypt((new String("thevalue")).getBytes(),
                                       (new String("mykey")).getBytes()));
    ...
    System.out.println("Base64 encoded String:" +
                       new sun.misc.BASE64Encoder().encode(c.getBytes()));
    

    What you are doing here is:

    1. Convert the plaintext string to bytes, using the system’s default encoding
    2. convert the key to bytes, using the system’s default encoding
    3. encrypt the bytes
    4. convert the encrypted bytes back to a string, using the system’s default encoding
    5. convert the encrypted string back to bytes, using the system’s default encoding
    6. encode these encrypted bytes using Base64.

    The problem is in step 4. It assumes that an arbitrary byte array represents a string in your system’s default encoding, and encoding this string back gives the same byte[]. This is valid for some encodings (the ISO-8859 series, for example), but not for others. In Java, when some byte (or byte sequence) is not representable in the given encoding, it will be replaced by some other character, which later for reconverting will be mapped to byte 63 (ASCII ?). Actually, the documentation even says:

    The behavior of this constructor when the given bytes are not valid in the default charset is unspecified.

    In your case, there is no reason to do this at all – simply use the bytes which your encrypt method outputs directly to convert them to Base64.

    byte[] encrypted = Test.encrypt("thevalue".getBytes(),
                                    "mykey".getBytes());
    System.out.println("Base64 encoded String:"+ new sun.misc.BASE64Encoder().encode(encrypted));
    

    (Also note that I removed the superfluous new String("...") constructor calls here, though this does not relate to your problem.)

    The point to remember: Never ever convert an arbitrary byte[], which did not come from encoding a string, to a string. Output of an encryption algorithm (and most other cryptographic algorithms, except decryption) certainly belongs to the category of data which should not be converted to a string.

    And never ever use the System’s default encoding, if you want portable programs.

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

Sidebar

Related Questions

I am working in a PHP app we have a particular string that we
I am working on a project where I need to undertake Blowfish encryption and
I have a program that is encrypted with Blowfish in a file and a
I have an algorithm that uses the following OpenSSL calls: HMAC_update() / HMAC_final() //
Have created simple Ajax enabled contact forms before that have around 12 fields -
Have a LinqtoSql query that I now want to precompile. var unorderedc = from
Openfire stores encrypted passwords in a database using blowfish encryption. http://svn.igniterealtime.org/svn/repos/openfire/trunk/src/java/org/jivesoftware/util/Blowfish.java is the java
I'm in need of a two-way encryption solution for Ruby, such as Blowfish, Rijndael
I have a secret key that was sent to me as a file so
I want to be able to create users that have a straight up SHA-1

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.