Package org.apache.xml.security.utils
Class Base64
- java.lang.Object
-
- org.apache.xml.security.utils.Base64
-
public class Base64 extends java.lang.ObjectImplementation 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:
- RFC 2045,
TransformBase64Decode
-
-
Field Summary
Fields Modifier and Type Field Description static intBASE64DEFAULTLENGTHField BASE64DEFAULTLENGTH
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]decode(byte[] base64)Method decodestatic voiddecode(byte[] base64Data, java.io.OutputStream os)Decodes Base64 data into outputstreamstatic byte[]decode(java.io.BufferedReader reader)Base64 decode the lines from the reader and return an InputStream with the bytes.static voiddecode(java.io.InputStream is, java.io.OutputStream os)Decodes Base64 data into outputstreamstatic byte[]decode(java.lang.String encoded)Decodes Base64 data into octectsstatic byte[]decode(org.w3c.dom.Element element)Method decode Takes theTextchildren of the Element and interprets them as input for theBase64.decode()function.static java.math.BigIntegerdecodeBigIntegerFromElement(org.w3c.dom.Element element)Method decodeBigIntegerFromElementstatic java.math.BigIntegerdecodeBigIntegerFromText(org.w3c.dom.Text text)Method decodeBigIntegerFromTextprotected static byte[]decodeInternal(byte[] base64Data)static java.lang.Stringencode(byte[] binaryData)Encode a byte array and fold lines at the standard 76th character.static java.lang.Stringencode(byte[] binaryData, int length)Encode a byte array in Base64 format and return an optionally wrapped line.static java.lang.Stringencode(java.math.BigInteger big)Encode in Base64 the givenBigInteger.static byte[]encode(java.math.BigInteger big, int bitlen)Returns a byte-array representation of aBigInteger.static org.w3c.dom.ElementencodeToElement(org.w3c.dom.Document doc, java.lang.String localName, byte[] bytes)Method encodeToElementstatic voidfillElementWithBigInteger(org.w3c.dom.Element element, java.math.BigInteger biginteger)This method takes an (empty) Element and a BigInteger and adds the base64 encoded BigInteger to the Element.protected static booleanisPad(byte octect)protected static booleanisWhiteSpace(byte octect)static voidmain(java.lang.String[] args)Method mainprotected static intremoveWhiteSpace(byte[] data)remove WhiteSpace from MIME containing encoded Base64 data.
-
-
-
Field Detail
-
BASE64DEFAULTLENGTH
public static final int BASE64DEFAULTLENGTH
Field BASE64DEFAULTLENGTH- See Also:
- Constant Field Values
-
-
Method Detail
-
encode
public static java.lang.String encode(java.math.BigInteger big)
Encode in Base64 the givenBigInteger.- Parameters:
big-- Returns:
- String with Base64 encoding
-
encode
public static byte[] encode(java.math.BigInteger big, int bitlen)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-BigIntegerto be convertedbitlen-intthe desired length in bits of the representation- Returns:
- a byte array with
bitlenbits ofbig
-
decodeBigIntegerFromElement
public static java.math.BigInteger decodeBigIntegerFromElement(org.w3c.dom.Element element) throws Base64DecodingExceptionMethod decodeBigIntegerFromElement- Parameters:
element-- Returns:
- the biginter obtained from the node
- Throws:
Base64DecodingException
-
decodeBigIntegerFromText
public static java.math.BigInteger decodeBigIntegerFromText(org.w3c.dom.Text text) throws Base64DecodingExceptionMethod decodeBigIntegerFromText- Parameters:
text-- Returns:
- the biginter obtained from the text node
- Throws:
Base64DecodingException
-
fillElementWithBigInteger
public static void fillElementWithBigInteger(org.w3c.dom.Element element, java.math.BigInteger biginteger)This method takes an (empty) Element and a BigInteger and adds the base64 encoded BigInteger to the Element.- Parameters:
element-biginteger-
-
decode
public static byte[] decode(org.w3c.dom.Element element) throws Base64DecodingExceptionMethod decode Takes theTextchildren 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
public static org.w3c.dom.Element encodeToElement(org.w3c.dom.Document doc, java.lang.String localName, byte[] bytes)Method encodeToElement- Parameters:
doc-localName-bytes-- Returns:
- an Element with the base64 encoded in the text.
-
decode
public static byte[] decode(byte[] base64) throws Base64DecodingExceptionMethod decode- Parameters:
base64-- Returns:
- the UTF bytes of the base64
- Throws:
Base64DecodingException
-
encode
public static java.lang.String encode(byte[] binaryData)
Encode a byte array and fold lines at the standard 76th character.- Parameters:
binaryData-byte[]to be base64 encoded- Returns:
- the
Stringwith encoded data
-
decode
public static byte[] decode(java.io.BufferedReader reader) throws java.io.IOException, Base64DecodingExceptionBase64 decode the lines from the reader and return an InputStream with the bytes.- Parameters:
reader-- Returns:
- InputStream with the decoded bytes
- Throws:
java.io.IOException- passes what the reader throwsjava.io.IOExceptionBase64DecodingException
-
main
public static void main(java.lang.String[] args) throws java.lang.ExceptionMethod main- Parameters:
args-- Throws:
java.lang.Exception
-
isWhiteSpace
protected static final boolean isWhiteSpace(byte octect)
-
isPad
protected static final boolean isPad(byte octect)
-
encode
public static java.lang.String encode(byte[] binaryData, int length)Encode a byte array in Base64 format and return an optionally wrapped line.- Parameters:
binaryData-byte[]data to be encodedlength-intlength of wrapped lines; No wrapping if less than 4.- Returns:
- a
Stringwith encoded data
-
decode
public static final byte[] decode(java.lang.String encoded) throws Base64DecodingExceptionDecodes Base64 data into octects- Parameters:
encoded- Byte array containing Base64 data- Returns:
- Array containind decoded data.
- Throws:
Base64DecodingException
-
decodeInternal
protected static final byte[] decodeInternal(byte[] base64Data) throws Base64DecodingException- Throws:
Base64DecodingException
-
decode
public static final void decode(byte[] base64Data, java.io.OutputStream os) throws Base64DecodingException, java.io.IOExceptionDecodes Base64 data into outputstream- Parameters:
base64Data- Byte array containing Base64 dataos- the outputstream- Throws:
java.io.IOExceptionBase64DecodingException
-
decode
public static final void decode(java.io.InputStream is, java.io.OutputStream os) throws Base64DecodingException, java.io.IOExceptionDecodes Base64 data into outputstream- Parameters:
is- containing Base64 dataos- the outputstream- Throws:
java.io.IOExceptionBase64DecodingException
-
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
-
-