com.sun.org.apache.xml.internal.security.exceptions.Base64DecodingException Java Examples

The following examples show how to use com.sun.org.apache.xml.internal.security.exceptions.Base64DecodingException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Base64.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * Method decode
 *
 * Takes the <CODE>Text</CODE> children of the Element and interprets
 * them as input for the <CODE>Base64.decode()</CODE> function.
 *
 * @param element
 * @return the byte obtained of the decoding the element
 * $todo$ not tested yet
 * @throws Base64DecodingException
 */
public static final byte[] decode(Element element) throws Base64DecodingException {

    Node sibling = element.getFirstChild();
    StringBuffer sb = new StringBuffer();

    while (sibling != null) {
        if (sibling.getNodeType() == Node.TEXT_NODE) {
            Text t = (Text) sibling;

            sb.append(t.getData());
        }
        sibling = sibling.getNextSibling();
    }

    return decode(sb.toString());
}
 
Example #2
Source File: DOMXMLSignature.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
DOMSignatureValue(Element sigValueElem, XMLCryptoContext context)
    throws MarshalException
{
    try {
        // base64 decode signatureValue
        value = Base64.decode(sigValueElem);
    } catch (Base64DecodingException bde) {
        throw new MarshalException(bde);
    }

    Attr attr = sigValueElem.getAttributeNodeNS(null, "Id");
    if (attr != null) {
        id = attr.getValue();
        sigValueElem.setIdAttributeNode(attr, true);
    } else {
        id = null;
    }
    this.sigValueElem = sigValueElem;
}
 
Example #3
Source File: Base64.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * Base64 decode the lines from the reader and return an InputStream
 * with the bytes.
 *
 * @param reader
 * @return InputStream with the decoded bytes
 * @exception IOException passes what the reader throws
 * @throws IOException
 * @throws Base64DecodingException
 */
public static final byte[] decode(BufferedReader reader)
    throws IOException, Base64DecodingException {

    byte[] retBytes = null;
    UnsyncByteArrayOutputStream baos = null;
    try {
        baos = new UnsyncByteArrayOutputStream();
        String line;

        while (null != (line = reader.readLine())) {
            byte[] bytes = decode(line);
            baos.write(bytes);
        }
        retBytes = baos.toByteArray();
    } finally {
        baos.close();
    }

    return retBytes;
}
 
Example #4
Source File: Base64.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Method decode
 *
 * Takes the <CODE>Text</CODE> children of the Element and interprets
 * them as input for the <CODE>Base64.decode()</CODE> function.
 *
 * @param element
 * @return the byte obtained of the decoding the element
 * $todo$ not tested yet
 * @throws Base64DecodingException
 */
public static final byte[] decode(Element element) throws Base64DecodingException {

    Node sibling = element.getFirstChild();
    StringBuffer sb = new StringBuffer();

    while (sibling != null) {
        if (sibling.getNodeType() == Node.TEXT_NODE) {
            Text t = (Text) sibling;

            sb.append(t.getData());
        }
        sibling = sibling.getNextSibling();
    }

    return decode(sb.toString());
}
 
Example #5
Source File: Base64.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Base64 decode the lines from the reader and return an InputStream
 * with the bytes.
 *
 * @param reader
 * @return InputStream with the decoded bytes
 * @exception IOException passes what the reader throws
 * @throws IOException
 * @throws Base64DecodingException
 */
public static final byte[] decode(BufferedReader reader)
    throws IOException, Base64DecodingException {

    byte[] retBytes = null;
    UnsyncByteArrayOutputStream baos = null;
    try {
        baos = new UnsyncByteArrayOutputStream();
        String line;

        while (null != (line = reader.readLine())) {
            byte[] bytes = decode(line);
            baos.write(bytes);
        }
        retBytes = baos.toByteArray();
    } finally {
        baos.close();
    }

    return retBytes;
}
 
Example #6
Source File: Base64.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Method decode
 *
 * Takes the <CODE>Text</CODE> children of the Element and interprets
 * them as input for the <CODE>Base64.decode()</CODE> function.
 *
 * @param element
 * @return the byte obtained of the decoding the element
 * $todo$ not tested yet
 * @throws Base64DecodingException
 */
public static final byte[] decode(Element element) throws Base64DecodingException {

    Node sibling = element.getFirstChild();
    StringBuffer sb = new StringBuffer();

    while (sibling != null) {
        if (sibling.getNodeType() == Node.TEXT_NODE) {
            Text t = (Text) sibling;

            sb.append(t.getData());
        }
        sibling = sibling.getNextSibling();
    }

    return decode(sb.toString());
}
 
Example #7
Source File: DOMXMLSignature.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
DOMSignatureValue(Element sigValueElem, XMLCryptoContext context)
    throws MarshalException
{
    try {
        // base64 decode signatureValue
        value = Base64.decode(sigValueElem);
    } catch (Base64DecodingException bde) {
        throw new MarshalException(bde);
    }

    Attr attr = sigValueElem.getAttributeNodeNS(null, "Id");
    if (attr != null) {
        id = attr.getValue();
        sigValueElem.setIdAttributeNode(attr, true);
    } else {
        id = null;
    }
    this.sigValueElem = sigValueElem;
}
 
Example #8
Source File: Base64.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Method decode
 *
 * Takes the <CODE>Text</CODE> children of the Element and interprets
 * them as input for the <CODE>Base64.decode()</CODE> function.
 *
 * @param element
 * @return the byte obtained of the decoding the element
 * $todo$ not tested yet
 * @throws Base64DecodingException
 */
public static final byte[] decode(Element element) throws Base64DecodingException {

    Node sibling = element.getFirstChild();
    StringBuffer sb = new StringBuffer();

    while (sibling != null) {
        if (sibling.getNodeType() == Node.TEXT_NODE) {
            Text t = (Text) sibling;

            sb.append(t.getData());
        }
        sibling = sibling.getNextSibling();
    }

    return decode(sb.toString());
}
 
Example #9
Source File: DOMXMLSignature.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
DOMSignatureValue(Element sigValueElem, XMLCryptoContext context)
    throws MarshalException
{
    try {
        // base64 decode signatureValue
        value = Base64.decode(sigValueElem);
    } catch (Base64DecodingException bde) {
        throw new MarshalException(bde);
    }

    Attr attr = sigValueElem.getAttributeNodeNS(null, "Id");
    if (attr != null) {
        id = attr.getValue();
        sigValueElem.setIdAttributeNode(attr, true);
    } else {
        id = null;
    }
    this.sigValueElem = sigValueElem;
}
 
Example #10
Source File: Base64.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Base64 decode the lines from the reader and return an InputStream
 * with the bytes.
 *
 * @param reader
 * @return InputStream with the decoded bytes
 * @exception IOException passes what the reader throws
 * @throws IOException
 * @throws Base64DecodingException
 */
public static final byte[] decode(BufferedReader reader)
    throws IOException, Base64DecodingException {

    byte[] retBytes = null;
    UnsyncByteArrayOutputStream baos = null;
    try {
        baos = new UnsyncByteArrayOutputStream();
        String line;

        while (null != (line = reader.readLine())) {
            byte[] bytes = decode(line);
            baos.write(bytes);
        }
        retBytes = baos.toByteArray();
    } finally {
        baos.close();
    }

    return retBytes;
}
 
Example #11
Source File: Base64.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Base64 decode the lines from the reader and return an InputStream
 * with the bytes.
 *
 * @param reader
 * @return InputStream with the decoded bytes
 * @exception IOException passes what the reader throws
 * @throws IOException
 * @throws Base64DecodingException
 */
public static final byte[] decode(BufferedReader reader)
    throws IOException, Base64DecodingException {

    byte[] retBytes = null;
    UnsyncByteArrayOutputStream baos = null;
    try {
        baos = new UnsyncByteArrayOutputStream();
        String line;

        while (null != (line = reader.readLine())) {
            byte[] bytes = decode(line);
            baos.write(bytes);
        }
        retBytes = baos.toByteArray();
    } finally {
        baos.close();
    }

    return retBytes;
}
 
Example #12
Source File: XMLSignature.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the octet value of the SignatureValue element.
 * Throws an XMLSignatureException if it has no or wrong content.
 *
 * @return the value of the SignatureValue element.
 * @throws XMLSignatureException If there is no content
 */
public byte[] getSignatureValue() throws XMLSignatureException {
    try {
        return Base64.decode(signatureValueElement);
    } catch (Base64DecodingException ex) {
        throw new XMLSignatureException("empty", ex);
    }
}
 
Example #13
Source File: XMLSignature.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the octet value of the SignatureValue element.
 * Throws an XMLSignatureException if it has no or wrong content.
 *
 * @return the value of the SignatureValue element.
 * @throws XMLSignatureException If there is no content
 */
public byte[] getSignatureValue() throws XMLSignatureException {
    try {
        return Base64.decode(signatureValueElement);
    } catch (Base64DecodingException ex) {
        throw new XMLSignatureException("empty", ex);
    }
}
 
Example #14
Source File: DOMX509Data.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a <code>DOMX509Data</code> from an element.
 *
 * @param xdElem an X509Data element
 * @throws MarshalException if there is an error while unmarshalling
 */
public DOMX509Data(Element xdElem) throws MarshalException {
    // get all children nodes
    NodeList nl = xdElem.getChildNodes();
    int length = nl.getLength();
    List<Object> content = new ArrayList<Object>(length);
    for (int i = 0; i < length; i++) {
        Node child = nl.item(i);
        // ignore all non-Element nodes
        if (child.getNodeType() != Node.ELEMENT_NODE) {
            continue;
        }

        Element childElem = (Element)child;
        String localName = childElem.getLocalName();
        if (localName.equals("X509Certificate")) {
            content.add(unmarshalX509Certificate(childElem));
        } else if (localName.equals("X509IssuerSerial")) {
            content.add(new DOMX509IssuerSerial(childElem));
        } else if (localName.equals("X509SubjectName")) {
            content.add(childElem.getFirstChild().getNodeValue());
        } else if (localName.equals("X509SKI")) {
            try {
                content.add(Base64.decode(childElem));
            } catch (Base64DecodingException bde) {
                throw new MarshalException("cannot decode X509SKI", bde);
            }
        } else if (localName.equals("X509CRL")) {
            content.add(unmarshalX509CRL(childElem));
        } else {
            content.add(new javax.xml.crypto.dom.DOMStructure(childElem));
        }
    }
    this.content = Collections.unmodifiableList(content);
}
 
Example #15
Source File: DOMX509Data.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private ByteArrayInputStream unmarshalBase64Binary(Element elem)
    throws MarshalException {
    try {
        if (cf == null) {
            cf = CertificateFactory.getInstance("X.509");
        }
        return new ByteArrayInputStream(Base64.decode(elem));
    } catch (CertificateException e) {
        throw new MarshalException("Cannot create CertificateFactory", e);
    } catch (Base64DecodingException bde) {
        throw new MarshalException("Cannot decode Base64-encoded val", bde);
    }
}
 
Example #16
Source File: Reference.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the digest value.
 *
 * @return the digest value.
 * @throws Base64DecodingException if Reference contains no proper base64 encoded data.
 * @throws XMLSecurityException if the Reference does not contain a DigestValue element
 */
public byte[] getDigestValue() throws Base64DecodingException, XMLSecurityException {
    if (digestValueElement == null) {
        // The required element is not in the XML!
        Object[] exArgs ={ Constants._TAG_DIGESTVALUE, Constants.SignatureSpecNS };
        throw new XMLSecurityException(
            "signature.Verification.NoSignatureElement", exArgs
        );
    }
    return Base64.decode(digestValueElement);
}
 
Example #17
Source File: ElementProxy.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Method getVal
 *
 * @param localname
 * @param namespace
 * @return The biginteger contained in the given element
 * @throws Base64DecodingException
 */
public BigInteger getBigIntegerFromChildElement(
    String localname, String namespace
) throws Base64DecodingException {
    return Base64.decodeBigIntegerFromText(
        XMLUtils.selectNodeText(
            this.constructionElement.getFirstChild(), namespace, localname, 0
        )
    );
}
 
Example #18
Source File: ElementProxy.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Method getVal
 *
 * @param localname
 * @param namespace
 * @return The biginteger contained in the given element
 * @throws Base64DecodingException
 */
public BigInteger getBigIntegerFromChildElement(
    String localname, String namespace
) throws Base64DecodingException {
    return Base64.decodeBigIntegerFromText(
        XMLUtils.selectNodeText(
            this.constructionElement.getFirstChild(), namespace, localname, 0
        )
    );
}
 
Example #19
Source File: XMLSignature.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the octet value of the SignatureValue element.
 * Throws an XMLSignatureException if it has no or wrong content.
 *
 * @return the value of the SignatureValue element.
 * @throws XMLSignatureException If there is no content
 */
public byte[] getSignatureValue() throws XMLSignatureException {
    try {
        return Base64.decode(signatureValueElement);
    } catch (Base64DecodingException ex) {
        throw new XMLSignatureException("empty", ex);
    }
}
 
Example #20
Source File: ElementProxy.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Method getVal
 *
 * @param localname
 * @param namespace
 * @return The biginteger contained in the given element
 * @throws Base64DecodingException
 */
public BigInteger getBigIntegerFromChildElement(
    String localname, String namespace
) throws Base64DecodingException {
    return Base64.decodeBigIntegerFromText(
        XMLUtils.selectNodeText(
            this.constructionElement.getFirstChild(), namespace, localname, 0
        )
    );
}
 
Example #21
Source File: Reference.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the digest value.
 *
 * @return the digest value.
 * @throws Base64DecodingException if Reference contains no proper base64 encoded data.
 * @throws XMLSecurityException if the Reference does not contain a DigestValue element
 */
public byte[] getDigestValue() throws Base64DecodingException, XMLSecurityException {
    if (digestValueElement == null) {
        // The required element is not in the XML!
        Object[] exArgs ={ Constants._TAG_DIGESTVALUE, Constants.SignatureSpecNS };
        throw new XMLSecurityException(
            "signature.Verification.NoSignatureElement", exArgs
        );
    }
    return Base64.decode(digestValueElement);
}
 
Example #22
Source File: DOMX509Data.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private ByteArrayInputStream unmarshalBase64Binary(Element elem)
    throws MarshalException {
    try {
        if (cf == null) {
            cf = CertificateFactory.getInstance("X.509");
        }
        return new ByteArrayInputStream(Base64.decode(elem));
    } catch (CertificateException e) {
        throw new MarshalException("Cannot create CertificateFactory", e);
    } catch (Base64DecodingException bde) {
        throw new MarshalException("Cannot decode Base64-encoded val", bde);
    }
}
 
Example #23
Source File: DOMX509Data.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a <code>DOMX509Data</code> from an element.
 *
 * @param xdElem an X509Data element
 * @throws MarshalException if there is an error while unmarshalling
 */
public DOMX509Data(Element xdElem) throws MarshalException {
    // get all children nodes
    NodeList nl = xdElem.getChildNodes();
    int length = nl.getLength();
    List<Object> content = new ArrayList<Object>(length);
    for (int i = 0; i < length; i++) {
        Node child = nl.item(i);
        // ignore all non-Element nodes
        if (child.getNodeType() != Node.ELEMENT_NODE) {
            continue;
        }

        Element childElem = (Element)child;
        String localName = childElem.getLocalName();
        if (localName.equals("X509Certificate")) {
            content.add(unmarshalX509Certificate(childElem));
        } else if (localName.equals("X509IssuerSerial")) {
            content.add(new DOMX509IssuerSerial(childElem));
        } else if (localName.equals("X509SubjectName")) {
            content.add(childElem.getFirstChild().getNodeValue());
        } else if (localName.equals("X509SKI")) {
            try {
                content.add(Base64.decode(childElem));
            } catch (Base64DecodingException bde) {
                throw new MarshalException("cannot decode X509SKI", bde);
            }
        } else if (localName.equals("X509CRL")) {
            content.add(unmarshalX509CRL(childElem));
        } else {
            content.add(new javax.xml.crypto.dom.DOMStructure(childElem));
        }
    }
    this.content = Collections.unmodifiableList(content);
}
 
Example #24
Source File: Reference.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Returns the digest value.
 *
 * @return the digest value.
 * @throws Base64DecodingException if Reference contains no proper base64 encoded data.
 * @throws XMLSecurityException if the Reference does not contain a DigestValue element
 */
public byte[] getDigestValue() throws Base64DecodingException, XMLSecurityException {
    if (digestValueElement == null) {
        // The required element is not in the XML!
        Object[] exArgs ={ Constants._TAG_DIGESTVALUE, Constants.SignatureSpecNS };
        throw new XMLSecurityException(
            "signature.Verification.NoSignatureElement", exArgs
        );
    }
    return Base64.decode(digestValueElement);
}
 
Example #25
Source File: DOMPGPData.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a <code>DOMPGPData</code> from an element.
 *
 * @param pdElem a PGPData element
 */
public DOMPGPData(Element pdElem) throws MarshalException {
    // get all children nodes
    byte[] keyId = null;
    byte[] keyPacket = null;
    NodeList nl = pdElem.getChildNodes();
    int length = nl.getLength();
    List<XMLStructure> other = new ArrayList<XMLStructure>(length);
    for (int x = 0; x < length; x++) {
        Node n = nl.item(x);
        if (n.getNodeType() == Node.ELEMENT_NODE) {
            Element childElem = (Element)n;
            String localName = childElem.getLocalName();
            try {
                if (localName.equals("PGPKeyID")) {
                    keyId = Base64.decode(childElem);
                } else if (localName.equals("PGPKeyPacket")){
                    keyPacket = Base64.decode(childElem);
                } else {
                    other.add
                        (new javax.xml.crypto.dom.DOMStructure(childElem));
                }
            } catch (Base64DecodingException bde) {
                throw new MarshalException(bde);
            }
        }
    }
    this.keyId = keyId;
    this.keyPacket = keyPacket;
    this.externalElements = Collections.unmodifiableList(other);
}
 
Example #26
Source File: Reference.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the digest value.
 *
 * @return the digest value.
 * @throws Base64DecodingException if Reference contains no proper base64 encoded data.
 * @throws XMLSecurityException if the Reference does not contain a DigestValue element
 */
public byte[] getDigestValue() throws Base64DecodingException, XMLSecurityException {
    if (digestValueElement == null) {
        // The required element is not in the XML!
        Object[] exArgs ={ Constants._TAG_DIGESTVALUE, Constants.SignatureSpecNS };
        throw new XMLSecurityException(
            "signature.Verification.NoSignatureElement", exArgs
        );
    }
    return Base64.decode(digestValueElement);
}
 
Example #27
Source File: ElementProxy.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Method getVal
 *
 * @param localname
 * @param namespace
 * @return The biginteger contained in the given element
 * @throws Base64DecodingException
 */
public BigInteger getBigIntegerFromChildElement(
    String localname, String namespace
) throws Base64DecodingException {
    return Base64.decodeBigIntegerFromText(
        XMLUtils.selectNodeText(
            this.constructionElement.getFirstChild(), namespace, localname, 0
        )
    );
}
 
Example #28
Source File: ElementProxy.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Method getVal
 *
 * @param localname
 * @param namespace
 * @return The biginteger contained in the given element
 * @throws Base64DecodingException
 */
public BigInteger getBigIntegerFromChildElement(
    String localname, String namespace
) throws Base64DecodingException {
    return Base64.decodeBigIntegerFromText(
        XMLUtils.selectNodeText(
            this.constructionElement.getFirstChild(), namespace, localname, 0
        )
    );
}
 
Example #29
Source File: XMLSignature.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the octet value of the SignatureValue element.
 * Throws an XMLSignatureException if it has no or wrong content.
 *
 * @return the value of the SignatureValue element.
 * @throws XMLSignatureException If there is no content
 */
public byte[] getSignatureValue() throws XMLSignatureException {
    try {
        return Base64.decode(signatureValueElement);
    } catch (Base64DecodingException ex) {
        throw new XMLSignatureException("empty", ex);
    }
}
 
Example #30
Source File: Base64.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Decodes Base64 data into octets
 *
 * @param encoded String containing base64 encoded data
 * @return byte array containing the decoded data
 * @throws Base64DecodingException if there is a problem decoding the data
 */
public static final byte[] decode(String encoded) throws Base64DecodingException {
    if (encoded == null) {
        return null;
    }
    byte[] bytes = new byte[encoded.length()];
    int len = getBytesInternal(encoded, bytes);
    return decodeInternal(bytes, len);
}