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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:45:00+00:00 2026-05-31T18:45:00+00:00

This is the PHP code I have. function decrypt($s_input, $s_key, $s_iv) { $s_decrypted =

  • 0

This is the PHP code I have.

function decrypt($s_input, $s_key, $s_iv) { 
   $s_decrypted = pack("H*" , $s_input); // Hex to binary
   $s_decrypted = mcrypt_decrypt (MCRYPT_3DES, $s_key, $s_decrypted, MCRYPT_MODE_CBC, $s_iv);  // 3des decryption
  return $s_decrypted; 
}
echo encrypt('c37551bb77f741d0bcdc16497b4f97b1','123456781234567812345678','12345678' );

what it basically does is to decrypt a 3des encrypted string (first it convert the hex string to binary using pack function and then does the actual decryption).

This perfectly works in PHP-4 and prints the “Hello World” message.

However, if I run the equivalent java code (jdk 1.6), it prints garbage output as – ¬ªmjV=7xl_ÓÄ^›*?.

Can someone help to troubleshoot this? Why Java is not properly decrypting the hex string.

private static String decrypt(String inputStr, String keyStr, String ivStr) throws Exception {

    IvParameterSpec iv = new IvParameterSpec(ivStr.getBytes());
    SecretKeySpec key = new SecretKeySpec(keyStr.getBytes(), "DESede");
    inputStr = hexToString(inputStr, 2);

    Cipher cipher = Cipher.getInstance("DESede/CBC/NoPadding");
    cipher.init(Cipher.DECRYPT_MODE, key, iv);
    byte[] decrypted = cipher.doFinal(inputStr.getBytes());

    return new String(decrypted);
}

private static String hexToString(String input, int groupLength) {
    StringBuilder sb = new StringBuilder(input.length() / groupLength);
    for (int i = 0; i < input.length() - groupLength + 1; i += groupLength) {
        String hex = input.substring(i, i + groupLength);
        sb.append((char) Integer.parseInt(hex, 16));
    }
    return sb.toString();
}

public static void main(String[] args) throws Exception {
    String decryptSignature = decrypt("c37551bb77f741d0bcdc16497b4f97b1", "123456781234567812345678", "12345678");
    System.out.println(decryptSignature);
}
  • 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-31T18:45:02+00:00Added an answer on May 31, 2026 at 6:45 pm

    There are a few things you should check. You might find Encryption using AES-128 in Java to be of some assistance. There could be issues with differences between how you are handling keys in the PHP and Java code. Calling getBytes() on a String in Java without an encoding is almost always a bad idea. Plus the padding used could be a problem. From what I’ve seen PHP pads with null characters by default, which does not correspond to NoPadding in Java. Finally, the hexToString method should return a byte[] instead of a String. Add the result of calling Integer.parseInt(hex, 16) into an array:

    byte[] results = new byte[input.length() / groupLength];
    ...
        //inside the loop
        results[i / groupLength] = (byte) Integer.parseInt(hex, 16);
    ...
    return results;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: function submitTwice(f){ f.action = 'http://mydomain.com/threevideopage.php'; f.target='name'; f.submit(); } I left
I have this code in userpage.php: <script langauge=JavaScript><!-- function newWindow(fileName,windowName) { msgWindow=window.open(fileName,windowName); } //--></script>
I have the following jquery code: jQuery(function(){ jQuery(select#rooms).change(function(){ var options = ''; jQuery.getJSON(/admin/selection.php,{id: jQuery(this).val(),
i need help with disk_total_space function.. i have this on my code <?php $sql=select
I have this PHP code (get_option is Wordpress function). <?php $hahaha = get_option('hahaha'); if(empty($hahaha))
I have this PHP code: function ShowFileExtension($filepath) { preg_match('/[^?]*/', $filepath, $matches); $string = $matches[0];
I need a little help with the fsockopen function. I have this PHP code:
Say i have this PHP code: $FooBar = a string; i then need a
I have this php code, with which I am trying to generate a popup
I have this PHP code echo '<a href=# onclick=updateByQuery(\'Layer3\', ' . json_encode($query) . ');>Link

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.