Package org.apache.xml.security.utils
Class Base64
java.lang.Object
org.apache.xml.security.utils.Base64
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)
- Author:
- Raul Benito(Of the xerces copy, and little adaptations)., Anli Shundi, Christian Geuer-Pollmann
- See Also:
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]
decode
(byte[] base64) Method decodestatic final void
decode
(byte[] base64Data, OutputStream os) Decodes Base64 data into outputstreamstatic byte[]
decode
(BufferedReader reader) Base64 decode the lines from the reader and return an InputStream with the bytes.static final void
decode
(InputStream is, OutputStream os) Decodes Base64 data into outputstreamstatic final byte[]
Decodes Base64 data into octectsstatic byte[]
Method decode Takes theText
children of the Element and interprets them as input for theBase64.decode()
function.static BigInteger
decodeBigIntegerFromElement
(Element element) Method decodeBigIntegerFromElementstatic BigInteger
decodeBigIntegerFromText
(Text text) Method decodeBigIntegerFromTextprotected static final byte[]
decodeInternal
(byte[] base64Data) static String
encode
(byte[] binaryData) Encode a byte array and fold lines at the standard 76th character.static String
encode
(byte[] binaryData, int length) Encode a byte array in Base64 format and return an optionally wrapped line.static String
encode
(BigInteger big) Encode in Base64 the givenBigInteger
.
static byte[]
encode
(BigInteger big, int bitlen) Returns a byte-array representation of aBigInteger
.
static Element
encodeToElement
(Document doc, String localName, byte[] bytes) Method encodeToElementstatic void
fillElementWithBigInteger
(Element element, BigInteger biginteger) This method takes an (empty) Element and a BigInteger and adds the base64 encoded BigInteger to the Element.protected static final boolean
isPad
(byte octect) protected static final boolean
isWhiteSpace
(byte octect) static void
Method mainprotected static int
removeWhiteSpace
(byte[] data) remove WhiteSpace from MIME containing encoded Base64 data.
-
Field Details
-
BASE64DEFAULTLENGTH
public static final int BASE64DEFAULTLENGTHField BASE64DEFAULTLENGTH- See Also:
-
-
Method Details
-
encode
Encode in Base64 the givenBigInteger
.
- Parameters:
big
-- Returns:
- String with Base64 encoding
-
encode
Returns a byte-array representation of aBigInteger
. No sign-bit is outputed. N.B.:
BigInteger
's toByteArray retunrs eventually longer arrays because of the leading sign-bit.
- Parameters:
big
-BigInteger
to be converted
bitlen
-int
the desired length in bits of the representation
- Returns:
- a byte array with
bitlen
bits ofbig
-
decodeBigIntegerFromElement
public static BigInteger decodeBigIntegerFromElement(Element element) throws Base64DecodingException Method decodeBigIntegerFromElement- Parameters:
element
-- Returns:
- the biginter obtained from the node
- Throws:
Base64DecodingException
-
decodeBigIntegerFromText
Method decodeBigIntegerFromText- Parameters:
text
-- Returns:
- the biginter obtained from the text node
- Throws:
Base64DecodingException
-
fillElementWithBigInteger
This method takes an (empty) Element and a BigInteger and adds the base64 encoded BigInteger to the Element.- Parameters:
element
-biginteger
-
-
decode
Method decode Takes theText
children of the Element and interprets them as input for theBase64.decode()
function.- Parameters:
element
-- Returns:
- the byte obtained of the decoding the element $todo$ not tested yet
- Throws:
Base64DecodingException
-
encodeToElement
Method encodeToElement- Parameters:
doc
-localName
-bytes
-- Returns:
- an Element with the base64 encoded in the text.
-
decode
Method decode- Parameters:
base64
-- Returns:
- the UTF bytes of the base64
- Throws:
Base64DecodingException
-
encode
Encode a byte array and fold lines at the standard 76th character.- Parameters:
binaryData
-byte[]
to be base64 encoded
- Returns:
- the
String
with encoded data
-
decode
Base64 decode the lines from the reader and return an InputStream with the bytes.- Parameters:
reader
-- Returns:
- InputStream with the decoded bytes
- Throws:
IOException
- passes what the reader throwsIOException
Base64DecodingException
-
main
Method main- Parameters:
args
-- Throws:
Exception
-
isWhiteSpace
protected static final boolean isWhiteSpace(byte octect) -
isPad
protected static final boolean isPad(byte octect) -
encode
Encode a byte array in Base64 format and return an optionally wrapped line.- Parameters:
binaryData
-byte[]
data to be encodedlength
-int
length of wrapped lines; No wrapping if less than 4.
- Returns:
- a
String
with encoded data
-
decode
Decodes Base64 data into octects- Parameters:
encoded
- Byte array containing Base64 data- Returns:
- Array containind decoded data.
- Throws:
Base64DecodingException
-
decodeInternal
- Throws:
Base64DecodingException
-
decode
public static final void decode(byte[] base64Data, OutputStream os) throws Base64DecodingException, IOException Decodes Base64 data into outputstream- Parameters:
base64Data
- Byte array containing Base64 dataos
- the outputstream- Throws:
IOException
Base64DecodingException
-
decode
public static final void decode(InputStream is, OutputStream os) throws Base64DecodingException, IOException Decodes Base64 data into outputstream- Parameters:
is
- containing Base64 dataos
- the outputstream- Throws:
IOException
Base64DecodingException
-
removeWhiteSpace
protected static int removeWhiteSpace(byte[] data) remove WhiteSpace from MIME containing encoded Base64 data.- Parameters:
data
- the byte array of base64 data (with WS)- Returns:
- the new length
-