-1

I have a base64 encoded string. "jZsq4NNN0K4HzssoDEakhImknSVHLWpsmIF2AEBNacLykXJWBK9VKmCuuX1SR5iMNlfqXe7/eP8oLFEZp50E3g=="

When I trying decode with php (base64_decode)

Result: ��*��M��(F�����%G-jl��v@Mi��rV�U*��}RG��6W�]��x�(,Q���`

When I trying with javascript (window.atob)

Result: *àÓMЮÎË(F¤¤%G-jlv@MiÂòrV¯U*®¹}RG6Wê]îÿxÿ(,Q§Þ"`

Now we came strange part.

Now I trying with JDK 1.8.0_201 (Base64.getDecoder().decode)

Result: [B@4e25154f

Now with JDK 1.8.0_66

Result: [B@2a139a55

Lets try with latest JDK (10.0.1),

Result: [B@6073f712

As you can see, different results in every version. I don't know why and I want to learn.

Edit:

  public static void main(String[] args)
  {
    String version = System.getProperty("java.version");
    System.out.print(version + " || " + decodeMeee());
  }
  private static String decodeMeee() {
    return newBase64.getDecoder().decode("jZsq4NNN0K4HzssoDEakhImknSVHLWpsmIF2AEBNacLykXJWBK9VKmCuuX1SR5iMNlfqXe7/eP8oLFEZp50E3g==");
    }

And now I tried same thing with converting manually. It seems go with the grain.

  public static void main(String[] args)
  {
    String version = System.getProperty("java.version");
    System.out.print(version + " || " + decodeMeee());
  }
  private static String decodeMeee() {
    return new String(Base64.getDecoder().decode("jZsq4NNN0K4HzssoDEakhImknSVHLWpsmIF2AEBNacLykXJWBK9VKmCuuX1SR5iMNlfqXe7/eP8oLFEZp50E3g=="));
    }
  • 4
    Add some code that shows how you decode it. Probably you're using the wrong encoding - try `utf-8`. – second Jul 26 '19 at 09:49
  • Please share the full code for all tests, this helps others to inspect your problem – Nico Haase Jul 26 '19 at 09:49
  • 2
    You're not calling the correct method to display your decoded string value or not using UTF-8. Please edit your post with your code. – Austin Schaefer Jul 26 '19 at 09:50
  • Regarding `[B@4e25154f` [What's the simplest way to print a Java array?](https://stackoverflow.com/q/409784). Also this may interest you: [How to convert byte array to string and vice versa?](https://stackoverflow.com/q/1536054) – Pshemo Jul 26 '19 at 09:52
  • Gomennasai! I added sample codes. – Cihan Çetin Jul 26 '19 at 09:53
  • The base64 string doesn't seem to include any printable chracters? Test yourself here: https://www.base64decode.org/ – Jesse Schokker Jul 26 '19 at 09:55
  • Actaully, my problem is not that. Why result changing in every jdk version when I return my data as byte[]? – Cihan Çetin Jul 26 '19 at 09:58
  • "Why result changing in every jdk version when I return my data as byte[]" are you are referring to `[B@4e25154f` and `[B@2a139a55`? Then they don't change based on JDK version, but based on current memory structure since it shows `Type@HexHashCode` and native hashcode of array is based on its memory location. – Pshemo Jul 26 '19 at 10:01
  • I understand. Thank you. – Cihan Çetin Jul 26 '19 at 10:18

1 Answers1

1

This is how you do it ..., so it's not UTF-8.

public class Main {

    public static void main(String[] args) throws UnsupportedEncodingException {
        String version = System.getProperty("java.version");
        System.out.print(version + " || " + decodeMeee());
    }

    private static String decodeMeee() throws UnsupportedEncodingException {
        byte[] content = Base64.getDecoder()
                .decode("jZsq4NNN0K4HzssoDEakhImknSVHLWpsmIF2AEBNacLykXJWBK9VKmCuuX1SR5iMNlfqXe7/eP8oLFEZp50E3g==");
        return new String(content, 0, content.length, "UTF-8"); // <-- replace with correct encoding format
    }
}

Prints:

12.0.2    || ��*��M��(F�����%G-jl��v
10.0.2    || ��*��M��(F�����%G-jl��v
1.8.0_151 || ��*��M��(F�����%G-jl��v

PS:

Lets try with latest JDK (10.0.1),

Definitely not the latest ;)

second
  • 4,069
  • 2
  • 9
  • 24