Java Code Examples for com.sun.org.apache.xml.internal.security.utils.Base64#decode()

The following examples show how to use com.sun.org.apache.xml.internal.security.utils.Base64#decode() . 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: DOMXMLSignature.java    From jdk8u-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 2
Source File: DOMXMLSignature.java    From openjdk-jdk8u 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: DOMXMLSignature.java    From openjdk-jdk9 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 4
Source File: DOMPGPData.java    From jdk8u_jdk 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 5
Source File: DOMPGPData.java    From openjdk-jdk8u 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 6
Source File: DOMX509Data.java    From hottub 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 7
Source File: Reference.java    From openjdk-jdk8u 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 8
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 9
Source File: DOMX509Data.java    From openjdk-jdk8u-backup 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 10
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 11
Source File: XMLSignature.java    From jdk8u_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 12
Source File: XMLSignature.java    From hottub 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: DOMX509Data.java    From TencentKona-8 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 14
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 15
Source File: DOMX509Data.java    From openjdk-jdk9 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: DOMPGPData.java    From dragonwell8_jdk 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 17
Source File: DOMPGPData.java    From openjdk-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 18
Source File: DOMPGPData.java    From openjdk-jdk9 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 19
Source File: DOMReference.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a <code>DOMReference</code> from an element.
 *
 * @param refElem a Reference element
 */
public DOMReference(Element refElem, XMLCryptoContext context,
                    Provider provider)
    throws MarshalException
{
    boolean secVal = Utils.secureValidation(context);

    // unmarshal Transforms, if specified
    Element nextSibling = DOMUtils.getFirstChildElement(refElem);
    List<Transform> transforms = new ArrayList<Transform>(5);
    if (nextSibling.getLocalName().equals("Transforms")) {
        Element transformElem = DOMUtils.getFirstChildElement(nextSibling,
                                                              "Transform");
        transforms.add(new DOMTransform(transformElem, context, provider));
        transformElem = DOMUtils.getNextSiblingElement(transformElem);
        while (transformElem != null) {
            String localName = transformElem.getLocalName();
            if (!localName.equals("Transform")) {
                throw new MarshalException(
                    "Invalid element name: " + localName +
                    ", expected Transform");
            }
            transforms.add
                (new DOMTransform(transformElem, context, provider));
            if (secVal && (transforms.size() > MAXIMUM_TRANSFORM_COUNT)) {
                String error = "A maxiumum of " + MAXIMUM_TRANSFORM_COUNT + " "
                    + "transforms per Reference are allowed with secure validation";
                throw new MarshalException(error);
            }
            transformElem = DOMUtils.getNextSiblingElement(transformElem);
        }
        nextSibling = DOMUtils.getNextSiblingElement(nextSibling);
    }
    if (!nextSibling.getLocalName().equals("DigestMethod")) {
        throw new MarshalException("Invalid element name: " +
                                   nextSibling.getLocalName() +
                                   ", expected DigestMethod");
    }

    // unmarshal DigestMethod
    Element dmElem = nextSibling;
    this.digestMethod = DOMDigestMethod.unmarshal(dmElem);
    String digestMethodAlgorithm = this.digestMethod.getAlgorithm();
    if (secVal
        && MessageDigestAlgorithm.ALGO_ID_DIGEST_NOT_RECOMMENDED_MD5.equals(digestMethodAlgorithm)) {
        throw new MarshalException(
            "It is forbidden to use algorithm " + digestMethod + " when secure validation is enabled"
        );
    }

    // unmarshal DigestValue
    Element dvElem = DOMUtils.getNextSiblingElement(dmElem, "DigestValue");
    try {
        this.digestValue = Base64.decode(dvElem);
    } catch (Base64DecodingException bde) {
        throw new MarshalException(bde);
    }

    // check for extra elements
    if (DOMUtils.getNextSiblingElement(dvElem) != null) {
        throw new MarshalException(
            "Unexpected element after DigestValue element");
    }

    // unmarshal attributes
    this.uri = DOMUtils.getAttributeValue(refElem, "URI");

    Attr attr = refElem.getAttributeNodeNS(null, "Id");
    if (attr != null) {
        this.id = attr.getValue();
        refElem.setIdAttributeNode(attr, true);
    } else {
        this.id = null;
    }

    this.type = DOMUtils.getAttributeValue(refElem, "Type");
    this.here = refElem.getAttributeNodeNS(null, "URI");
    this.refElem = refElem;
    this.transforms = transforms;
    this.allTransforms = transforms;
    this.appliedTransformData = null;
    this.provider = provider;
}
 
Example 20
Source File: DOMReference.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a <code>DOMReference</code> from an element.
 *
 * @param refElem a Reference element
 */
public DOMReference(Element refElem, XMLCryptoContext context,
                    Provider provider)
    throws MarshalException
{
    boolean secVal = Utils.secureValidation(context);

    // unmarshal Transforms, if specified
    Element nextSibling = DOMUtils.getFirstChildElement(refElem);
    List<Transform> transforms = new ArrayList<Transform>(5);
    if (nextSibling.getLocalName().equals("Transforms")) {
        Element transformElem = DOMUtils.getFirstChildElement(nextSibling,
                                                              "Transform");
        transforms.add(new DOMTransform(transformElem, context, provider));
        transformElem = DOMUtils.getNextSiblingElement(transformElem);
        while (transformElem != null) {
            String localName = transformElem.getLocalName();
            if (!localName.equals("Transform")) {
                throw new MarshalException(
                    "Invalid element name: " + localName +
                    ", expected Transform");
            }
            transforms.add
                (new DOMTransform(transformElem, context, provider));
            if (secVal && Policy.restrictNumTransforms(transforms.size())) {
                String error = "A maximum of " + Policy.maxTransforms()
                    + " transforms per Reference are allowed when"
                    + " secure validation is enabled";
                throw new MarshalException(error);
            }
            transformElem = DOMUtils.getNextSiblingElement(transformElem);
        }
        nextSibling = DOMUtils.getNextSiblingElement(nextSibling);
    }
    if (!nextSibling.getLocalName().equals("DigestMethod")) {
        throw new MarshalException("Invalid element name: " +
                                   nextSibling.getLocalName() +
                                   ", expected DigestMethod");
    }

    // unmarshal DigestMethod
    Element dmElem = nextSibling;
    this.digestMethod = DOMDigestMethod.unmarshal(dmElem);
    String digestMethodAlgorithm = this.digestMethod.getAlgorithm();
    if (secVal && Policy.restrictAlg(digestMethodAlgorithm)) {
        throw new MarshalException(
            "It is forbidden to use algorithm " + digestMethodAlgorithm +
            " when secure validation is enabled"
        );
    }

    // unmarshal DigestValue
    Element dvElem = DOMUtils.getNextSiblingElement(dmElem, "DigestValue");
    try {
        this.digestValue = Base64.decode(dvElem);
    } catch (Base64DecodingException bde) {
        throw new MarshalException(bde);
    }

    // check for extra elements
    if (DOMUtils.getNextSiblingElement(dvElem) != null) {
        throw new MarshalException(
            "Unexpected element after DigestValue element");
    }

    // unmarshal attributes
    this.uri = DOMUtils.getAttributeValue(refElem, "URI");

    Attr attr = refElem.getAttributeNodeNS(null, "Id");
    if (attr != null) {
        this.id = attr.getValue();
        refElem.setIdAttributeNode(attr, true);
    } else {
        this.id = null;
    }

    this.type = DOMUtils.getAttributeValue(refElem, "Type");
    this.here = refElem.getAttributeNodeNS(null, "URI");
    this.refElem = refElem;
    this.transforms = transforms;
    this.allTransforms = transforms;
    this.appliedTransformData = null;
    this.provider = provider;
}