Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create base64Binary data?

What is base64Binary and how can I create base64Binary from a given byte array in Java?

like image 765
siva636 Avatar asked Aug 11 '11 15:08

siva636


People also ask

What is base64Binary in XML?

base64Binary represents binary data encoded in Base64. Its value space is the set of fixed length binary octets. Its lexical space is limited to a-z , A-Z , 0-9 , + , / , = , plus whitespace. string represents character data. Its value space is the set of finite-length sequences of characters.

How do I encode to base 64?

If we were to Base64 encode a string we would follow these steps: Take the ASCII value of each character in the string. Calculate the 8-bit binary equivalent of the ASCII values. Convert the 8-bit chunks into chunks of 6 bits by simply re-grouping the digits.

What is base 64 encoding used for?

Base64 encoding schemes are commonly used when there is a need to encode binary data that needs to be stored and transferred over media that are designed to deal with ASCII. This is to ensure that the data remain intact without modification during transport.


2 Answers

To create such data you may use the JDK built-in class sun.misc.BASE64Encoder. Unfortunately it's not public API since nobody cared to provide a BASE64 en-/decoder in the public API - but people often use this class to circumvent that disadvantage.

base64Binary is an XML Schema data type, referring to arbitrary binary data that is to be encoded using BASE64 encoding to retrieve a "safe" string representation of that data - e.g. for embedding binary data in XML, mails etc.

W3C Definition:

base64Binary represents Base64-encoded arbitrary binary data. The ·value space· of base64Binary is the set of finite-length sequences of binary octets. For base64Binary data the entire binary stream is encoded using the Base64 Alphabet in [RFC 2045].

like image 80
emboss Avatar answered Oct 13 '22 05:10

emboss


Try commons-codec with public static byte[] encodeBase64(byte[] binaryData).

like image 34
Matthijs Bierman Avatar answered Oct 13 '22 06:10

Matthijs Bierman