Decodificador Base64 Pdf
As of Java 8, there is an officially supported API for Base64 encoding and decoding. In time this will probably become the default choice. The API includes the class and its nested classes. Quidam The Time Beneath The Sky Rar on this page.
It supports three different flavors: basic, URL safe, and MIME. Sample code using the 'basic' encoding: import java.util.Base64; byte[] bytes = 'Hello, World!'
.getBytes('UTF-8'); String encoded = Base64.getEncoder().encodeToString(bytes); byte[] decoded = Base64.getDecoder().decode(encoded); The includes several more methods for configuring encoders and decoders, and for using different classes as inputs and outputs (byte arrays, strings, ByteBuffers, java.io streams). I do NOT recommend providing these methods to users. For example let's just look at your encode method. It takes a String. Already we're in trouble. By turning bytes[] into String and then encoding you've already potentially corrupted the original bytes of the File or whatever else it is you're encoding. It's better to just let them use the raw Base64.encodeBase64String(byte[]) method that way they will avoid corrupting bytes as they convert them to base64 and back out again.
Decode and Encode Base64 data with this online base64 decoder.
Just my 0.02 cents. – Nov 23 '16 at 17:28. No need to use commons--Sun ships a base64 encoder with Java. You can import it as such: import sun.misc.BASE64Decoder; And then use it like this: BASE64Decoder decoder = new BASE64Decoder(); byte[] decodedBytes = decoder.decodeBuffer(encodedBytes); Where encodedBytes is either a java.lang.String or a java.io.InputStream. Just beware that the sun.* classes are not 'officially supported' by Sun. EDIT: Who knew this would be the most controversial answer I'd ever post?
I do know that sun.* packages are not supported or guaranteed to continue existing, and I do know about Commons and use it all the time. However, the poster asked for a class that that was 'included with Sun Java 6,' and that's what I was trying to answer. I agree that Commons is the best way to go in general. EDIT 2: As amir75 points out below, Java 6+ ships with JAXB, which contains supported code to encode/decode Base64. Please see below.