What is base64Binary and how can I create base64Binary from a given byte array in Java?
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.
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.
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.
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].
Try commons-codec with public static byte[] encodeBase64(byte[] binaryData)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With