APIdia Launch Partner
Top Description Fields Constructors Methods
com.sun.org.apache.xml.internal.security.utils

public final Class Base64

extends Object
Class Inheritance
Annotations
@Deprecated
@SuppressWarnings:PMD
Imports
java.io.BufferedReader, .IOException, .InputStream, .OutputStream, java.math.BigInteger, com.sun.org.apache.xml.internal.security.exceptions.Base64DecodingException, org.w3c.dom.Document, .Element, .Node, .Text

Deprecated

Implementation of MIME's Base64 encoding and decoding conversions. Optimized code. (raw version taken from oreilly.jonathan.util, and currently org.apache.xerces.ds.util.Base64)
See Also
RFC 2045, com.sun.org.apache.xml.internal.security.transforms.implementations.TransformBase64Decode

Field Summary

Modifier and TypeField and Description
private static final byte[]
public static final int
BASE64DEFAULTLENGTH

Field BASE64DEFAULTLENGTH

private static final int
private static final int
private static final int
private static final char[]
private static final int
private static final char
private static final int
private static final int
private static final int

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static byte[]

Returns:

the byte obtained of the decoding the element $todo$ not tested yet
decode
(Element element)

Method decode Takes the Text children of the Element and interprets them as input for the Base64.decode() function.

public static byte[]

Returns:

the UTF bytes of the base64
decode
(byte[] base64)

Method decode

public static byte[]

Returns:

InputStream with the decoded bytes
decode
(BufferedReader reader)

Base64 decode the lines from the reader and return an InputStream with the bytes.

public static byte[]

Returns:

byte array containing the decoded data
decode
(String
String containing base64 encoded data
encoded
)

Decodes Base64 data into octets

public static void
decode(String
String containing Base64 data
base64Data
,
OutputStream
the outputstream
os
)

Decodes Base64 data into outputstream

public static void
decode(byte[]
Byte array containing Base64 data
base64Data
,
OutputStream
the outputstream
os
)

Decodes Base64 data into outputstream

protected static void
decode(byte[] base64Data, OutputStream os, int len)

public static void
decode(InputStream
containing Base64 data
is
,
OutputStream
the outputstream
os
)

Decodes Base64 data into outputstream

public static BigInteger

Returns:

the biginteger obtained from the node
decodeBigIntegerFromElement
(Element element)

Method decodeBigIntegerFromElement

public static BigInteger

Returns:

a decoded BigInteger
decodeBigIntegerFromText
(Text
Base 64 encoded text.
text
)

Decode a base 64 string into a BigInteger

protected static byte[]
decodeInternal(byte[] base64Data, int len)

public static String

Returns:

String with Base64 encoding
encode
(BigInteger big)

Encode in Base64 the given {@link BigInteger}.

public static byte[]

Returns:

a byte array with bitlen bits of big
encode
(BigInteger
BigInteger to be converted
big
,
int
int the desired length in bits of the representation
bitlen
)

Returns a byte-array representation of a {@link BigInteger}.

public static String

Returns:

the String with encoded data
encode
(byte[]
byte[] to be base64 encoded
binaryData
)

Encode a byte array and fold lines at the standard 76th character unless ignore line breaks property is set.

public static String

Returns:

a String with encoded data
encode
(byte[]
byte[] data to be encoded
binaryData
,
int
int length of wrapped lines; No wrapping if less than 4.
length
)

Encode a byte array in Base64 format and return an optionally wrapped line.

public static Element

Returns:

an Element with the base64 encoded in the text.
encodeToElement
(Document doc, String localName, byte[] bytes)

Method encodeToElement

public static void
fillElementWithBigInteger(Element element, BigInteger biginteger)

This method takes an (empty) Element and a BigInteger and adds the base64 encoded BigInteger to the Element.

pack-priv static byte[]

Returns:

a byte array with bitlen bits of big
getBytes
(BigInteger
BigInteger to be converted
big
,
int
int the desired length in bits of the representation
bitlen
)

Returns a byte-array representation of a BigInteger.

protected static int
getBytesInternal(String s, byte[] result)

protected static boolean
isPad(byte octet)

protected static boolean
isWhiteSpace(byte octet)

protected static int

Returns:

the new length
removeWhiteSpace
(byte[]
the byte array of base64 data (with WS)
data
)

remove WhiteSpace from MIME containing encoded Base64 data.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

base64Alphabetback to summary
private static final byte[] base64Alphabet
BASE64DEFAULTLENGTHback to summary
public static final int BASE64DEFAULTLENGTH

Field BASE64DEFAULTLENGTH

BASELENGTHback to summary
private static final int BASELENGTH
EIGHTBITback to summary
private static final int EIGHTBIT
FOURBYTEback to summary
private static final int FOURBYTE
lookUpBase64Alphabetback to summary
private static final char[] lookUpBase64Alphabet
LOOKUPLENGTHback to summary
private static final int LOOKUPLENGTH
PADback to summary
private static final char PAD
SIGNback to summary
private static final int SIGN
SIXTEENBITback to summary
private static final int SIXTEENBIT
TWENTYFOURBITGROUPback to summary
private static final int TWENTYFOURBITGROUP

Constructor Detail

Base64back to summary
private Base64()

Method Detail

decodeback to summary
public static byte[] decode(Element element) throws Base64DecodingException

Method decode Takes the Text children of the Element and interprets them as input for the Base64.decode() function.

Returns:byte[]

the byte obtained of the decoding the element $todo$ not tested yet

decodeback to summary
public static byte[] decode(byte[] base64) throws Base64DecodingException

Method decode

Returns:byte[]

the UTF bytes of the base64

decodeback to summary
public static byte[] decode(BufferedReader reader) throws IOException, Base64DecodingException

Base64 decode the lines from the reader and return an InputStream with the bytes.

Returns:byte[]

InputStream with the decoded bytes

Exceptions
IOException:
passes what the reader throws
decodeback to summary
public static byte[] decode(String encoded) throws Base64DecodingException

Decodes Base64 data into octets

Parameters
encoded:String

String containing base64 encoded data

Returns:byte[]

byte array containing the decoded data

Exceptions
Base64DecodingException:
if there is a problem decoding the data
decodeback to summary
public static void decode(String base64Data, OutputStream os) throws Base64DecodingException, IOException

Decodes Base64 data into outputstream

Parameters
base64Data:String

String containing Base64 data

os:OutputStream

the outputstream

decodeback to summary
public static void decode(byte[] base64Data, OutputStream os) throws Base64DecodingException, IOException

Decodes Base64 data into outputstream

Parameters
base64Data:byte[]

Byte array containing Base64 data

os:OutputStream

the outputstream

decodeback to summary
protected static void decode(byte[] base64Data, OutputStream os, int len) throws Base64DecodingException, IOException
decodeback to summary
public static void decode(InputStream is, OutputStream os) throws Base64DecodingException, IOException

Decodes Base64 data into outputstream

Parameters
is:InputStream

containing Base64 data

os:OutputStream

the outputstream

decodeBigIntegerFromElementback to summary
public static BigInteger decodeBigIntegerFromElement(Element element) throws Base64DecodingException

Method decodeBigIntegerFromElement

Returns:BigInteger

the biginteger obtained from the node

decodeBigIntegerFromTextback to summary
public static BigInteger decodeBigIntegerFromText(Text text) throws Base64DecodingException

Decode a base 64 string into a BigInteger

Parameters
text:Text

Base 64 encoded text.

Returns:BigInteger

a decoded BigInteger

decodeInternalback to summary
protected static byte[] decodeInternal(byte[] base64Data, int len) throws Base64DecodingException
encodeback to summary
public static String encode(BigInteger big)

Encode in Base64 the given {@link BigInteger}.

Returns:String

String with Base64 encoding

encodeback to summary
public static byte[] encode(BigInteger big, int bitlen)

Returns a byte-array representation of a {@link BigInteger}. No sign-bit is output

Note

{@link BigInteger}'s toByteArray returns eventually longer arrays because of the leading sign-bit.

Parameters
big:BigInteger

BigInteger to be converted

bitlen:int

int the desired length in bits of the representation

Returns:byte[]

a byte array with bitlen bits of big

encodeback to summary
public static String encode(byte[] binaryData)

Encode a byte array and fold lines at the standard 76th character unless ignore line breaks property is set.

Parameters
binaryData:byte[]

byte[] to be base64 encoded

Returns:String

the String with encoded data

encodeback to summary
public static String encode(byte[] binaryData, int length)

Encode a byte array in Base64 format and return an optionally wrapped line.

Parameters
binaryData:byte[]

byte[] data to be encoded

length:int

int length of wrapped lines; No wrapping if less than 4.

Returns:String

a String with encoded data

encodeToElementback to summary
public static Element encodeToElement(Document doc, String localName, byte[] bytes)

Method encodeToElement

Returns:Element

an Element with the base64 encoded in the text.

fillElementWithBigIntegerback to summary
public static void fillElementWithBigInteger(Element element, BigInteger biginteger)

This method takes an (empty) Element and a BigInteger and adds the base64 encoded BigInteger to the Element.

getBytesback to summary
pack-priv static byte[] getBytes(BigInteger big, int bitlen)

Returns a byte-array representation of a BigInteger. No sign-bit is output

Note

BigInteger's toByteArray returns eventually longer arrays because of the leading sign-bit.

Parameters
big:BigInteger

BigInteger to be converted

bitlen:int

int the desired length in bits of the representation

Returns:byte[]

a byte array with bitlen bits of big

getBytesInternalback to summary
protected static int getBytesInternal(String s, byte[] result)
isPadback to summary
protected static boolean isPad(byte octet)
isWhiteSpaceback to summary
protected static boolean isWhiteSpace(byte octet)
removeWhiteSpaceback to summary
protected static int removeWhiteSpace(byte[] data)

remove WhiteSpace from MIME containing encoded Base64 data.

Parameters
data:byte[]

the byte array of base64 data (with WS)

Returns:int

the new length