com.sun.org.apache.xml.internal.security.utils.Base64 Java Examples

The following examples show how to use com.sun.org.apache.xml.internal.security.utils.Base64. 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: XMLSignature.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Base64 encodes and sets the bytes as the content of the SignatureValue
 * Node.
 *
 * @param bytes bytes to be used by SignatureValue before Base64 encoding
 */
private void setSignatureValueElement(byte[] bytes) {

    while (signatureValueElement.hasChildNodes()) {
        signatureValueElement.removeChild(signatureValueElement.getFirstChild());
    }

    String base64codedValue = Base64.encode(bytes);

    if (base64codedValue.length() > 76 && !XMLUtils.ignoreLineBreaks()) {
        base64codedValue = "\n" + base64codedValue + "\n";
    }

    Text t = this.doc.createTextNode(base64codedValue);
    signatureValueElement.appendChild(t);
}
 
Example #2
Source File: XMLSignature.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * Base64 encodes and sets the bytes as the content of the SignatureValue
 * Node.
 *
 * @param bytes bytes to be used by SignatureValue before Base64 encoding
 */
private void setSignatureValueElement(byte[] bytes) {

    while (signatureValueElement.hasChildNodes()) {
        signatureValueElement.removeChild(signatureValueElement.getFirstChild());
    }

    String base64codedValue = Base64.encode(bytes);

    if (base64codedValue.length() > 76 && !XMLUtils.ignoreLineBreaks()) {
        base64codedValue = "\n" + base64codedValue + "\n";
    }

    Text t = this.doc.createTextNode(base64codedValue);
    signatureValueElement.appendChild(t);
}
 
Example #3
Source File: Reference.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Tests reference validation is success or false
 *
 * @return true if reference validation is success, otherwise false
 * @throws ReferenceNotInitializedException
 * @throws XMLSecurityException
 */
public boolean verify()
    throws ReferenceNotInitializedException, XMLSecurityException {
    byte[] elemDig = this.getDigestValue();
    byte[] calcDig = this.calculateDigest(true);
    boolean equal = MessageDigestAlgorithm.isEqual(elemDig, calcDig);

    if (!equal) {
        log.log(java.util.logging.Level.WARNING, "Verification failed for URI \"" + this.getURI() + "\"");
        log.log(java.util.logging.Level.WARNING, "Expected Digest: " + Base64.encode(elemDig));
        log.log(java.util.logging.Level.WARNING, "Actual Digest: " + Base64.encode(calcDig));
    } else {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "Verification successful for URI \"" + this.getURI() + "\"");
        }
    }

    return equal;
}
 
Example #4
Source File: Reference.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests reference validation is success or false
 *
 * @return true if reference validation is success, otherwise false
 * @throws ReferenceNotInitializedException
 * @throws XMLSecurityException
 */
public boolean verify()
    throws ReferenceNotInitializedException, XMLSecurityException {
    byte[] elemDig = this.getDigestValue();
    byte[] calcDig = this.calculateDigest(true);
    boolean equal = MessageDigestAlgorithm.isEqual(elemDig, calcDig);

    if (!equal) {
        log.log(java.util.logging.Level.WARNING, "Verification failed for URI \"" + this.getURI() + "\"");
        log.log(java.util.logging.Level.WARNING, "Expected Digest: " + Base64.encode(elemDig));
        log.log(java.util.logging.Level.WARNING, "Actual Digest: " + Base64.encode(calcDig));
    } else {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "Verification successful for URI \"" + this.getURI() + "\"");
        }
    }

    return equal;
}
 
Example #5
Source File: Reference.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Tests reference validation is success or false
 *
 * @return true if reference validation is success, otherwise false
 * @throws ReferenceNotInitializedException
 * @throws XMLSecurityException
 */
public boolean verify()
    throws ReferenceNotInitializedException, XMLSecurityException {
    byte[] elemDig = this.getDigestValue();
    byte[] calcDig = this.calculateDigest(true);
    boolean equal = MessageDigestAlgorithm.isEqual(elemDig, calcDig);

    if (!equal) {
        log.log(java.util.logging.Level.WARNING, "Verification failed for URI \"" + this.getURI() + "\"");
        log.log(java.util.logging.Level.WARNING, "Expected Digest: " + Base64.encode(elemDig));
        log.log(java.util.logging.Level.WARNING, "Actual Digest: " + Base64.encode(calcDig));
    } else {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "Verification successful for URI \"" + this.getURI() + "\"");
        }
    }

    return equal;
}
 
Example #6
Source File: DOMReference.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public boolean validate(XMLValidateContext validateContext)
    throws XMLSignatureException
{
    if (validateContext == null) {
        throw new NullPointerException("validateContext cannot be null");
    }
    if (validated) {
        return validationStatus;
    }
    Data data = dereference(validateContext);
    calcDigestValue = transform(data, validateContext);

    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "Expected digest: " + Base64.encode(digestValue));
        log.log(java.util.logging.Level.FINE, "Actual digest: " + Base64.encode(calcDigestValue));
    }

    validationStatus = Arrays.equals(digestValue, calcDigestValue);
    validated = true;
    return validationStatus;
}
 
Example #7
Source File: Reference.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Tests reference validation is success or false
 *
 * @return true if reference validation is success, otherwise false
 * @throws ReferenceNotInitializedException
 * @throws XMLSecurityException
 */
public boolean verify()
    throws ReferenceNotInitializedException, XMLSecurityException {
    byte[] elemDig = this.getDigestValue();
    byte[] calcDig = this.calculateDigest(true);
    boolean equal = MessageDigestAlgorithm.isEqual(elemDig, calcDig);

    if (!equal) {
        log.log(java.util.logging.Level.WARNING, "Verification failed for URI \"" + this.getURI() + "\"");
        log.log(java.util.logging.Level.WARNING, "Expected Digest: " + Base64.encode(elemDig));
        log.log(java.util.logging.Level.WARNING, "Actual Digest: " + Base64.encode(calcDig));
    } else {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "Verification successful for URI \"" + this.getURI() + "\"");
        }
    }

    return equal;
}
 
Example #8
Source File: XMLSignature.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Base64 encodes and sets the bytes as the content of the SignatureValue
 * Node.
 *
 * @param bytes bytes to be used by SignatureValue before Base64 encoding
 */
private void setSignatureValueElement(byte[] bytes) {

    while (signatureValueElement.hasChildNodes()) {
        signatureValueElement.removeChild(signatureValueElement.getFirstChild());
    }

    String base64codedValue = Base64.encode(bytes);

    if (base64codedValue.length() > 76 && !XMLUtils.ignoreLineBreaks()) {
        base64codedValue = "\n" + base64codedValue + "\n";
    }

    Text t = this.doc.createTextNode(base64codedValue);
    signatureValueElement.appendChild(t);
}
 
Example #9
Source File: URLHelper.java    From r2m-plugin-android with Apache License 2.0 6 votes vote down vote up
public static String checkURLConnection(String urlS, String username, String password){
    String status = "Error connection to server!";
    FormattedLogger logger = new FormattedLogger(URLHelper.class);
    logger.append("checkURLConnection:" + urlS);
    try {
        URL url = new URL(urlS);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();

        if (username != null && username.trim().length() > 0 && password != null && password.trim().length() > 0) {
            final String authString = username + ":" + password;
            conn.setRequestProperty("Authorization", "Basic " + Base64.encode(authString.getBytes()));
        }

        conn.setRequestMethod("GET");
        conn.setDoInput(true);

        status = "" + conn.getResponseCode();
        logger.append("Response code:" + status);
        logger.showInfoLog();
    } catch (Exception e) {
        logger.append(">>>" +  e.getClass().getName() + " message: " + e.getMessage());
        logger.showErrorLog();
    }
    return status;
}
 
Example #10
Source File: Reference.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Tests reference validation is success or false
 *
 * @return true if reference validation is success, otherwise false
 * @throws ReferenceNotInitializedException
 * @throws XMLSecurityException
 */
public boolean verify()
    throws ReferenceNotInitializedException, XMLSecurityException {
    byte[] elemDig = this.getDigestValue();
    byte[] calcDig = this.calculateDigest(true);
    boolean equal = MessageDigestAlgorithm.isEqual(elemDig, calcDig);

    if (!equal) {
        log.log(java.util.logging.Level.WARNING, "Verification failed for URI \"" + this.getURI() + "\"");
        log.log(java.util.logging.Level.WARNING, "Expected Digest: " + Base64.encode(elemDig));
        log.log(java.util.logging.Level.WARNING, "Actual Digest: " + Base64.encode(calcDig));
    } else {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "Verification successful for URI \"" + this.getURI() + "\"");
        }
    }

    return equal;
}
 
Example #11
Source File: Reference.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Tests reference validation is success or false
 *
 * @return true if reference validation is success, otherwise false
 * @throws ReferenceNotInitializedException
 * @throws XMLSecurityException
 */
public boolean verify()
    throws ReferenceNotInitializedException, XMLSecurityException {
    byte[] elemDig = this.getDigestValue();
    byte[] calcDig = this.calculateDigest(true);
    boolean equal = MessageDigestAlgorithm.isEqual(elemDig, calcDig);

    if (!equal) {
        log.log(java.util.logging.Level.WARNING, "Verification failed for URI \"" + this.getURI() + "\"");
        log.log(java.util.logging.Level.WARNING, "Expected Digest: " + Base64.encode(elemDig));
        log.log(java.util.logging.Level.WARNING, "Actual Digest: " + Base64.encode(calcDig));
    } else {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "Verification successful for URI \"" + this.getURI() + "\"");
        }
    }

    return equal;
}
 
Example #12
Source File: CertsInFilesystemDirectoryResolver.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Method main
 *
 * @param unused
 * @throws Exception
 */
public static void main(String unused[]) throws Exception {

    CertsInFilesystemDirectoryResolver krs =
        new CertsInFilesystemDirectoryResolver(
            "data/ie/baltimore/merlin-examples/merlin-xmldsig-eighteen/certs");

    for (Iterator<Certificate> i = krs.getIterator(); i.hasNext(); ) {
        X509Certificate cert = (X509Certificate) i.next();
        byte[] ski =
            com.sun.org.apache.xml.internal.security.keys.content.x509.XMLX509SKI.getSKIBytesFromCert(cert);

        System.out.println();
        System.out.println("Base64(SKI())=                 \""
                           + Base64.encode(ski) + "\"");
        System.out.println("cert.getSerialNumber()=        \""
                           + cert.getSerialNumber().toString() + "\"");
        System.out.println("cert.getSubjectX500Principal().getName()= \""
                           + cert.getSubjectX500Principal().getName() + "\"");
        System.out.println("cert.getIssuerX500Principal().getName()=  \""
                           + cert.getIssuerX500Principal().getName() + "\"");
    }
}
 
Example #13
Source File: CertsInFilesystemDirectoryResolver.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Method main
 *
 * @param unused
 * @throws Exception
 */
public static void main(String unused[]) throws Exception {

    CertsInFilesystemDirectoryResolver krs =
        new CertsInFilesystemDirectoryResolver(
            "data/ie/baltimore/merlin-examples/merlin-xmldsig-eighteen/certs");

    for (Iterator<Certificate> i = krs.getIterator(); i.hasNext(); ) {
        X509Certificate cert = (X509Certificate) i.next();
        byte[] ski =
            com.sun.org.apache.xml.internal.security.keys.content.x509.XMLX509SKI.getSKIBytesFromCert(cert);

        System.out.println();
        System.out.println("Base64(SKI())=                 \""
                           + Base64.encode(ski) + "\"");
        System.out.println("cert.getSerialNumber()=        \""
                           + cert.getSerialNumber().toString() + "\"");
        System.out.println("cert.getSubjectX500Principal().getName()= \""
                           + cert.getSubjectX500Principal().getName() + "\"");
        System.out.println("cert.getIssuerX500Principal().getName()=  \""
                           + cert.getIssuerX500Principal().getName() + "\"");
    }
}
 
Example #14
Source File: RangerMasterKey.java    From ranger with Apache License 2.0 6 votes vote down vote up
private String decryptMasterKey(byte masterKey[], String password, String encryptedPassString) throws Throwable {
    if (logger.isDebugEnabled()) {
        logger.debug("==> RangerMasterKey.decryptMasterKey()");
        logger.debug("Decrypting Master Key...");
    }
    if (encryptedPassString == null) {
        getPasswordParam(password);
    }
    PBEKeySpec pbeKeyspec = getPBEParameterSpec(password);
    byte[] masterKeyFromDBDecrypted = decryptKey(masterKey, pbeKeyspec);
    SecretKey masterKeyFromDB = getMasterKeyFromBytes(masterKeyFromDBDecrypted);
    if (logger.isDebugEnabled()) {
        logger.debug("<== RangerMasterKey.decryptMasterKey()");
    }
    return Base64.encode(masterKeyFromDB.getEncoded());
}
 
Example #15
Source File: CertsInFilesystemDirectoryResolver.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Method main
 *
 * @param unused
 * @throws Exception
 */
public static void main(String unused[]) throws Exception {

    CertsInFilesystemDirectoryResolver krs =
        new CertsInFilesystemDirectoryResolver(
            "data/ie/baltimore/merlin-examples/merlin-xmldsig-eighteen/certs");

    for (Iterator<Certificate> i = krs.getIterator(); i.hasNext(); ) {
        X509Certificate cert = (X509Certificate) i.next();
        byte[] ski =
            com.sun.org.apache.xml.internal.security.keys.content.x509.XMLX509SKI.getSKIBytesFromCert(cert);

        System.out.println();
        System.out.println("Base64(SKI())=                 \""
                           + Base64.encode(ski) + "\"");
        System.out.println("cert.getSerialNumber()=        \""
                           + cert.getSerialNumber().toString() + "\"");
        System.out.println("cert.getSubjectX500Principal().getName()= \""
                           + cert.getSubjectX500Principal().getName() + "\"");
        System.out.println("cert.getIssuerX500Principal().getName()=  \""
                           + cert.getIssuerX500Principal().getName() + "\"");
    }
}
 
Example #16
Source File: DOMReference.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public boolean validate(XMLValidateContext validateContext)
    throws XMLSignatureException
{
    if (validateContext == null) {
        throw new NullPointerException("validateContext cannot be null");
    }
    if (validated) {
        return validationStatus;
    }
    Data data = dereference(validateContext);
    calcDigestValue = transform(data, validateContext);

    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "Expected digest: " + Base64.encode(digestValue));
        log.log(java.util.logging.Level.FINE, "Actual digest: " + Base64.encode(calcDigestValue));
    }

    validationStatus = Arrays.equals(digestValue, calcDigestValue);
    validated = true;
    return validationStatus;
}
 
Example #17
Source File: CertsInFilesystemDirectoryResolver.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Method main
 *
 * @param unused
 * @throws Exception
 */
public static void main(String unused[]) throws Exception {

    CertsInFilesystemDirectoryResolver krs =
        new CertsInFilesystemDirectoryResolver(
            "data/ie/baltimore/merlin-examples/merlin-xmldsig-eighteen/certs");

    for (Iterator<Certificate> i = krs.getIterator(); i.hasNext(); ) {
        X509Certificate cert = (X509Certificate) i.next();
        byte[] ski =
            com.sun.org.apache.xml.internal.security.keys.content.x509.XMLX509SKI.getSKIBytesFromCert(cert);

        System.out.println();
        System.out.println("Base64(SKI())=                 \""
                           + Base64.encode(ski) + "\"");
        System.out.println("cert.getSerialNumber()=        \""
                           + cert.getSerialNumber().toString() + "\"");
        System.out.println("cert.getSubjectX500Principal().getName()= \""
                           + cert.getSubjectX500Principal().getName() + "\"");
        System.out.println("cert.getIssuerX500Principal().getName()=  \""
                           + cert.getIssuerX500Principal().getName() + "\"");
    }
}
 
Example #18
Source File: DOMReference.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public boolean validate(XMLValidateContext validateContext)
    throws XMLSignatureException
{
    if (validateContext == null) {
        throw new NullPointerException("validateContext cannot be null");
    }
    if (validated) {
        return validationStatus;
    }
    Data data = dereference(validateContext);
    calcDigestValue = transform(data, validateContext);

    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "Expected digest: " + Base64.encode(digestValue));
        log.log(java.util.logging.Level.FINE, "Actual digest: " + Base64.encode(calcDigestValue));
    }

    validationStatus = Arrays.equals(digestValue, calcDigestValue);
    validated = true;
    return validationStatus;
}
 
Example #19
Source File: DOMReference.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public boolean validate(XMLValidateContext validateContext)
    throws XMLSignatureException
{
    if (validateContext == null) {
        throw new NullPointerException("validateContext cannot be null");
    }
    if (validated) {
        return validationStatus;
    }
    Data data = dereference(validateContext);
    calcDigestValue = transform(data, validateContext);

    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "Expected digest: " + Base64.encode(digestValue));
        log.log(java.util.logging.Level.FINE, "Actual digest: " + Base64.encode(calcDigestValue));
    }

    validationStatus = Arrays.equals(digestValue, calcDigestValue);
    validated = true;
    return validationStatus;
}
 
Example #20
Source File: XMLX509SKI.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Method getSKIBytesFromCert
 *
 * @param cert
 * @return ski bytes from the given certificate
 *
 * @throws XMLSecurityException
 * @see java.security.cert.X509Extension#getExtensionValue(java.lang.String)
 */
public static byte[] getSKIBytesFromCert(X509Certificate cert)
    throws XMLSecurityException {

    if (cert.getVersion() < 3) {
        Object exArgs[] = { Integer.valueOf(cert.getVersion()) };
        throw new XMLSecurityException("certificate.noSki.lowVersion", exArgs);
    }

    /*
     * Gets the DER-encoded OCTET string for the extension value
     * (extnValue) identified by the passed-in oid String. The oid
     * string is represented by a set of positive whole numbers
     * separated by periods.
     */
    byte[] extensionValue = cert.getExtensionValue(XMLX509SKI.SKI_OID);
    if (extensionValue == null) {
        throw new XMLSecurityException("certificate.noSki.null");
    }

    /**
     * Strip away first four bytes from the extensionValue
     * The first two bytes are the tag and length of the extensionValue
     * OCTET STRING, and the next two bytes are the tag and length of
     * the ski OCTET STRING.
     */
    byte skidValue[] = new byte[extensionValue.length - 4];

    System.arraycopy(extensionValue, 4, skidValue, 0, skidValue.length);

    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "Base64 of SKI is " + Base64.encode(skidValue));
    }

    return skidValue;
}
 
Example #21
Source File: DOMReference.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void digest(XMLSignContext signContext)
    throws XMLSignatureException
{
    Data data = null;
    if (appliedTransformData == null) {
        data = dereference(signContext);
    } else {
        data = appliedTransformData;
    }
    digestValue = transform(data, signContext);

    // insert digestValue into DigestValue element
    String encodedDV = Base64.encode(digestValue);
    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "Reference object uri = " + uri);
    }
    Element digestElem = DOMUtils.getLastChildElement(refElem);
    if (digestElem == null) {
        throw new XMLSignatureException("DigestValue element expected");
    }
    DOMUtils.removeAllChildren(digestElem);
    digestElem.appendChild
        (refElem.getOwnerDocument().createTextNode(encodedDV));

    digested = true;
    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "Reference digesting completed");
    }
}
 
Example #22
Source File: Reference.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Method setDigestValueElement
 *
 * @param digestValue
 */
private void setDigestValueElement(byte[] digestValue) {
    Node n = digestValueElement.getFirstChild();
    while (n != null) {
        digestValueElement.removeChild(n);
        n = n.getNextSibling();
    }

    String base64codedValue = Base64.encode(digestValue);
    Text t = this.doc.createTextNode(base64codedValue);

    digestValueElement.appendChild(t);
}
 
Example #23
Source File: DOMPGPData.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public void marshal(Node parent, String dsPrefix, DOMCryptoContext context)
    throws MarshalException
{
    Document ownerDoc = DOMUtils.getOwnerDocument(parent);
    Element pdElem = DOMUtils.createElement(ownerDoc, "PGPData",
                                            XMLSignature.XMLNS, dsPrefix);

    // create and append PGPKeyID element
    if (keyId != null) {
        Element keyIdElem = DOMUtils.createElement(ownerDoc, "PGPKeyID",
                                                   XMLSignature.XMLNS,
                                                   dsPrefix);
        keyIdElem.appendChild
            (ownerDoc.createTextNode(Base64.encode(keyId)));
        pdElem.appendChild(keyIdElem);
    }

    // create and append PGPKeyPacket element
    if (keyPacket != null) {
        Element keyPktElem = DOMUtils.createElement(ownerDoc,
                                                    "PGPKeyPacket",
                                                    XMLSignature.XMLNS,
                                                    dsPrefix);
        keyPktElem.appendChild
            (ownerDoc.createTextNode(Base64.encode(keyPacket)));
        pdElem.appendChild(keyPktElem);
    }

    // create and append any elements
    for (XMLStructure extElem : externalElements) {
        DOMUtils.appendChild(pdElem, ((javax.xml.crypto.dom.DOMStructure)
            extElem).getNode());
    }

    parent.appendChild(pdElem);
}
 
Example #24
Source File: DOMReference.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void digest(XMLSignContext signContext)
    throws XMLSignatureException
{
    Data data = null;
    if (appliedTransformData == null) {
        data = dereference(signContext);
    } else {
        data = appliedTransformData;
    }
    digestValue = transform(data, signContext);

    // insert digestValue into DigestValue element
    String encodedDV = Base64.encode(digestValue);
    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "Reference object uri = " + uri);
    }
    Element digestElem = DOMUtils.getLastChildElement(refElem);
    if (digestElem == null) {
        throw new XMLSignatureException("DigestValue element expected");
    }
    DOMUtils.removeAllChildren(digestElem);
    digestElem.appendChild
        (refElem.getOwnerDocument().createTextNode(encodedDV));

    digested = true;
    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "Reference digesting completed");
    }
}
 
Example #25
Source File: Reference.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Method setDigestValueElement
 *
 * @param digestValue
 */
private void setDigestValueElement(byte[] digestValue) {
    Node n = digestValueElement.getFirstChild();
    while (n != null) {
        digestValueElement.removeChild(n);
        n = n.getNextSibling();
    }

    String base64codedValue = Base64.encode(digestValue);
    Text t = this.doc.createTextNode(base64codedValue);

    digestValueElement.appendChild(t);
}
 
Example #26
Source File: DOMX509Data.java    From openjdk-8-source 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 #27
Source File: MetadataCacher.java    From compiler with Apache License 2.0 5 votes vote down vote up
public boolean authenticate(String username, String password) {
	String authenStr = username + ":" + password;
	String encodedAuthenStr = Base64.encode(authenStr.getBytes());
	this.connection.setRequestProperty("Authorization", "Basic " + encodedAuthenStr);
	try {
		this.responseCode = this.connection.getResponseCode();
		this.authenticated = (this.responseCode / 100 == 2);
	} catch (IOException e) {
		// considered as failed
	}
	return this.authenticated;
}
 
Example #28
Source File: DOMX509Data.java    From openjdk-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 #29
Source File: DOMX509Data.java    From jdk8u-jdk 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 #30
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);
}