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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:03:53+00:00 2026-06-18T22:03:53+00:00

How can I convert this byte[] to String : byte[] mytest = new byte[]

  • 0

How can I convert this byte[] to String :

byte[] mytest = new byte[] {100,25,28,-122,-26,94,-3,-26};

i get this : "d��^�" when I use :

new String( mytest , "UTF-8" )

Here is code java for creation of key :

m_key = new javax.crypto.spec.SecretKeySpec(new byte[] {100,25,28,-122,-26,94,-3,-26}, "DES");

Thanks.

  • 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-18T22:03:55+00:00Added an answer on June 18, 2026 at 10:03 pm

    In order to decode the byte array into something like ASCII, you need to know its original encoding. Otherwise you would need to treat it as binary.

    Note: Base64 is intended for transferring binary data across networks.

    I would suggest Base64 encoding your byte array. Then in your PHP code decoding the Base64 string back into a UTF-8 string.

    In Java, here’s how to Base64 encode your byte array and then decode it back to UTF-8:

    import org.apache.commons.codec.binary.Base64;
    
    public class MyTest {
        public static void main(String[] args) throws Exception {
            byte[] byteArray = new byte[] {100,25,28,-122,-26,94,-3,-26};
            System.out.println("To UTF-8 string: " + new String(byteArray, "UTF-8"));
    
            byte[] base64 = Base64.encodeBase64(byteArray);
            System.out.println("To Base64 string: " + new String(base64, "UTF-8"));
    
            byte[] decoded = Base64.decodeBase64(base64);
            System.out.println("Back to UTF-8 string: " + new String(decoded, "UTF-8"));
    
            /* the decoded byte array is the same as the original byte array */
            for (int i = 0; i < decoded.length; i++) {
                assert byteArray[i] == decoded[i];
            }
        }
    }

    The output from the above code is:

    To UTF-8 string: d��^�
    To Base64 string: ZBkchuZe/eY=
    Back to UTF-8 string: d��^�

    So if you wanted to use the same binary data in your PHP code, cut and paste the Base64 string into your PHP code and decode it back to UTF-8. Something like this:

    <?php
    $str = 'ZBkchuZe/eY=';
    $key = base64_decode($str);
    echo $key;
    ?>

    I don’t code in PHP, but you should be able to decode Base64 using this method:
    http://php.net/manual/en/function.base64-decode.php

    The above code should echo back the original binary data as UTF-8 (albeit with funny characters). The point is that the funny-looking string in the $key variable is representing the same binary data you had in the Java byte array:

    d��^�

    You should be able to pass the $key variable into your PHP encryption method.

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

Sidebar

Related Questions

How can I convert string to utf8 byte array, I have this sample code:
How can I convert this string into a byte? string a = 0x2B; I
I need to convert this java code in force.com apex. i tried to use
How can I convert this segment of C# code to C++/CLI: protected string GetMD5HashFromFile(string
How can I convert a Class to byte array in C#. This is a
is there anyway that I can convert this to use RSA encryption? im kinda
Can anyone convert this curl command that works in command line to php code
How can I convert this type of Arraylist to Two Dimensional Arraylist ? ArrayList<ArrayList<String>>
I have this piece of code: byte[] bytes = ... // Here my bytes.Lenght
I used to use this function to convert hex string to string in Delphi

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.