Check the character set that the encoders (Java and PHP) are using.
JavaDoc for the : getBytes() method of the String class.
Encodes this String into a sequence of bytes using the platform's default charset, storing the result into a new byte array.
The behavior of this method when this string cannot be encoded in the default charset is unspecified.
The java.nio.charset.CharsetEncoder class should be used when more control over the encoding process is required.
Returns:The resultant byte array
Since:JDK1.1
If you want to use a specific character set, you can pass it over to the method:
"test".getBytes(StandardCharsets.UTF_8);
Example This code produces two different values:
String s = "ec65450a-5:5217e"; System.out.println(Base64.getEncoder().encodeToString(s.getBytes())); System.out.println(Base64.getEncoder().encodeToString(s.getBytes(StandardCharsets.UTF_8))); System.out.println(Base64.getEncoder().encodeToString(s.getBytes(StandardCharsets.UTF_16)));
Output
ZWM2NTQ1MGEtNTo1MjE3ZQ==
ZWM2NTQ1MGEtNTo1MjE3ZQ==
/v8AZQBjADYANQA0ADUAMABhAC0ANQA6ADUAMgAxADcAZQ==
The first two are the same, because getBytes() uses the platform's default charset, and it happens to be UTF-8
Ideone.comsnippet and another for PHP and paste in the link?implode('', $bytes)I don't think this is what you want. This gives you a string of integer byte values, like10099for stringef. This can't be reversed on the server side because "10,199" and "101,99" encode to the same thing. I think you just wantbase64_encode($string).