There is unfortunately not just one Base64 encoding. The -
character doesn't have the same representation in all encodings. For example, in the MIME encoding, it's not used at all. In the encoding for URLs, it is a value of 62--and this is the one that Python is using. The default sun.misc decoder wants +
for 62. If you change the -
to +
, you get the correct answer (i.e. the Python answer).
In Scala, you can convert the string s
to MIME format like so:
s.map{ case '-' => '+'; case '_' => '/'; case c => c }
and then the Java MIME decoder will work.