3

I've been using the BASE64Encoder and BASE64Decoder in sun.misc; I'm using Eclipse and had to turn to warnings since the access is restricted to it by default.

The classes works perfectly, but during my work with this I've read plenty of places that one should not use sun.misc at all but no one states a proper reason.

Should I stay away from sun.misc and why?

Makoto
  • 104,088
  • 27
  • 192
  • 230
Rayf
  • 451
  • 3
  • 12
  • 1
    "encryption"? Base64 is about as safe as Rot13, that is someone who ran against a wall with their head one time too often may be confused when seeing it, but for anyone else it's trivial to "crack" and notice. Since there's a supported Base64 encoder in Java since Java5 or so (JAXB package), there really is no reason to use sun/oracle interna. – Voo Jul 08 '12 at 00:08
  • 1
    I hope that when you say "encryption", you're not referring to Base64. This is an encoding scheme, not an encryption, and doesn't really need cracking, but simply decoding. – oxc Jul 08 '12 at 00:09
  • I know. Merged it with a secretKeySpec using an Cipher with AES, that why I say in the end. – Rayf Jul 08 '12 at 00:14
  • 3
    I found a great alternative to sun.misc, org.apache.commons.codec.* http://commons.apache.org/codec/index.html Whenever I export a project Im just exporting the archive for commons.codec with it, avoiding future issues of Deprecated. – Rayf Jul 08 '12 at 00:59
  • There is no need to use that class since [Java 8 provided a supported (public) encoder](https://stackoverflow.com/questions/13109588/base64-encoding-in-java). – Raedwald Jun 04 '19 at 11:32

1 Answers1

7

There is no promise to continue support for these classes; they may be removed from the JDK without warning at any release.

Also, not all JDKs have these classes, so your code may not run on all platforms, which goes against the intention of java's "compile once, run anywhere" philosophy.

Bohemian
  • 412,405
  • 93
  • 575
  • 722
  • Thanks, just what I needed. Is there a alternative to BASE64Encoder/Decoder which is still supported that i've missed? – Rayf Jul 08 '12 at 00:11
  • 3
    @user1509396 `javax.xml.bind.DatatypeConverter` has static methods for it since java5 or 6 – Voo Jul 08 '12 at 00:13