Java Code Examples for javax.xml.crypto.dsig.keyinfo.KeyInfoFactory#getInstance()

The following examples show how to use javax.xml.crypto.dsig.keyinfo.KeyInfoFactory#getInstance() . 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: GetInstanceTests.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void TestKeyInfoFactory() throws Exception {
    KeyInfoFactory fac = KeyInfoFactory.getInstance();
    Provider p = fac.getProvider();
    String mechType = fac.getMechanismType();
    Provider p2;
    try {
        fac = KeyInfoFactory.getInstance(mechType);
        p2 = fac.getProvider();
        fac = KeyInfoFactory.getInstance(mechType, p);
        fac = KeyInfoFactory.getInstance(mechType, p.getName());
    } catch (Exception ex) {
        throw new RuntimeException("Error: Unexpected exception", ex);
    }
    if (p2.getName() != p.getName()) {
        throw new RuntimeException("Error: Provider equality check failed");
    }
}
 
Example 2
Source File: Marshal.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    KeyInfoFactory fac = KeyInfoFactory.getInstance();
    KeyInfo ki = fac.newKeyInfo
        (Collections.singletonList(fac.newKeyName("foo")), "keyid");
    try {
        ki.marshal(null, null);
        throw new Exception("Should raise a NullPointerException");
    } catch (NullPointerException npe) {}

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    Document doc = dbf.newDocumentBuilder().newDocument();
    Element elem = doc.createElementNS("http://acme.org", "parent");
    doc.appendChild(elem);
    DOMStructure parent = new DOMStructure(elem);
    ki.marshal(parent, null);

    Element kiElem = DOMUtils.getFirstChildElement(elem);
    if (!kiElem.getLocalName().equals("KeyInfo")) {
        throw new Exception
            ("Should be KeyInfo element: " + kiElem.getLocalName());
    }
    Element knElem = DOMUtils.getFirstChildElement(kiElem);
    if (!knElem.getLocalName().equals("KeyName")) {
        throw new Exception
            ("Should be KeyName element: " + knElem.getLocalName());
    }
}
 
Example 3
Source File: Marshal.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    KeyInfoFactory fac = KeyInfoFactory.getInstance();
    KeyInfo ki = fac.newKeyInfo
        (Collections.singletonList(fac.newKeyName("foo")), "keyid");
    try {
        ki.marshal(null, null);
        throw new Exception("Should raise a NullPointerException");
    } catch (NullPointerException npe) {}

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    Document doc = dbf.newDocumentBuilder().newDocument();
    Element elem = doc.createElementNS("http://acme.org", "parent");
    doc.appendChild(elem);
    DOMStructure parent = new DOMStructure(elem);
    ki.marshal(parent, null);

    Element kiElem = DOMUtils.getFirstChildElement(elem);
    if (!kiElem.getLocalName().equals("KeyInfo")) {
        throw new Exception
            ("Should be KeyInfo element: " + kiElem.getLocalName());
    }
    Element knElem = DOMUtils.getFirstChildElement(kiElem);
    if (!knElem.getLocalName().equals("KeyName")) {
        throw new Exception
            ("Should be KeyName element: " + knElem.getLocalName());
    }
}
 
Example 4
Source File: Marshal.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    KeyInfoFactory fac = KeyInfoFactory.getInstance();
    KeyInfo ki = fac.newKeyInfo
        (Collections.singletonList(fac.newKeyName("foo")), "keyid");
    try {
        ki.marshal(null, null);
        throw new Exception("Should raise a NullPointerException");
    } catch (NullPointerException npe) {}

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    Document doc = dbf.newDocumentBuilder().newDocument();
    Element elem = doc.createElementNS("http://acme.org", "parent");
    doc.appendChild(elem);
    DOMStructure parent = new DOMStructure(elem);
    ki.marshal(parent, null);

    Element kiElem = DOMUtils.getFirstChildElement(elem);
    if (!kiElem.getLocalName().equals("KeyInfo")) {
        throw new Exception
            ("Should be KeyInfo element: " + kiElem.getLocalName());
    }
    Element knElem = DOMUtils.getFirstChildElement(kiElem);
    if (!knElem.getLocalName().equals("KeyName")) {
        throw new Exception
            ("Should be KeyName element: " + knElem.getLocalName());
    }
}
 
Example 5
Source File: Marshal.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    KeyInfoFactory fac = KeyInfoFactory.getInstance();
    KeyInfo ki = fac.newKeyInfo
        (Collections.singletonList(fac.newKeyName("foo")), "keyid");
    try {
        ki.marshal(null, null);
        throw new Exception("Should raise a NullPointerException");
    } catch (NullPointerException npe) {}

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    Document doc = dbf.newDocumentBuilder().newDocument();
    Element elem = doc.createElementNS("http://acme.org", "parent");
    doc.appendChild(elem);
    DOMStructure parent = new DOMStructure(elem);
    ki.marshal(parent, null);

    Element kiElem = DOMUtils.getFirstChildElement(elem);
    if (!kiElem.getLocalName().equals("KeyInfo")) {
        throw new Exception
            ("Should be KeyInfo element: " + kiElem.getLocalName());
    }
    Element knElem = DOMUtils.getFirstChildElement(kiElem);
    if (!knElem.getLocalName().equals("KeyName")) {
        throw new Exception
            ("Should be KeyName element: " + knElem.getLocalName());
    }
}
 
Example 6
Source File: UnknownProvider.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    try {
        KeyInfoFactory fac = KeyInfoFactory.getInstance(
            "DOM", "SomeProviderThatDoesNotExist");
    }
    catch(NoSuchProviderException e) {
        // this is expected
    }
}
 
Example 7
Source File: Marshal.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    KeyInfoFactory fac = KeyInfoFactory.getInstance();
    KeyInfo ki = fac.newKeyInfo
        (Collections.singletonList(fac.newKeyName("foo")), "keyid");
    try {
        ki.marshal(null, null);
        throw new Exception("Should raise a NullPointerException");
    } catch (NullPointerException npe) {}

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    Document doc = dbf.newDocumentBuilder().newDocument();
    Element elem = doc.createElementNS("http://acme.org", "parent");
    doc.appendChild(elem);
    DOMStructure parent = new DOMStructure(elem);
    ki.marshal(parent, null);

    Element kiElem = DOMUtils.getFirstChildElement(elem);
    if (!kiElem.getLocalName().equals("KeyInfo")) {
        throw new Exception
            ("Should be KeyInfo element: " + kiElem.getLocalName());
    }
    Element knElem = DOMUtils.getFirstChildElement(kiElem);
    if (!knElem.getLocalName().equals("KeyName")) {
        throw new Exception
            ("Should be KeyName element: " + knElem.getLocalName());
    }
}
 
Example 8
Source File: Marshal.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    KeyInfoFactory fac = KeyInfoFactory.getInstance();
    KeyInfo ki = fac.newKeyInfo
        (Collections.singletonList(fac.newKeyName("foo")), "keyid");
    try {
        ki.marshal(null, null);
        throw new Exception("Should raise a NullPointerException");
    } catch (NullPointerException npe) {}

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    Document doc = dbf.newDocumentBuilder().newDocument();
    Element elem = doc.createElementNS("http://acme.org", "parent");
    doc.appendChild(elem);
    DOMStructure parent = new DOMStructure(elem);
    ki.marshal(parent, null);

    Element kiElem = DOMUtils.getFirstChildElement(elem);
    if (!kiElem.getLocalName().equals("KeyInfo")) {
        throw new Exception
            ("Should be KeyInfo element: " + kiElem.getLocalName());
    }
    Element knElem = DOMUtils.getFirstChildElement(kiElem);
    if (!knElem.getLocalName().equals("KeyName")) {
        throw new Exception
            ("Should be KeyName element: " + knElem.getLocalName());
    }
}
 
Example 9
Source File: Marshal.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    KeyInfoFactory fac = KeyInfoFactory.getInstance();
    KeyInfo ki = fac.newKeyInfo
        (Collections.singletonList(fac.newKeyName("foo")), "keyid");
    try {
        ki.marshal(null, null);
        throw new Exception("Should raise a NullPointerException");
    } catch (NullPointerException npe) {}

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    Document doc = dbf.newDocumentBuilder().newDocument();
    Element elem = doc.createElementNS("http://acme.org", "parent");
    doc.appendChild(elem);
    DOMStructure parent = new DOMStructure(elem);
    ki.marshal(parent, null);

    Element kiElem = DOMUtils.getFirstChildElement(elem);
    if (!kiElem.getLocalName().equals("KeyInfo")) {
        throw new Exception
            ("Should be KeyInfo element: " + kiElem.getLocalName());
    }
    Element knElem = DOMUtils.getFirstChildElement(kiElem);
    if (!knElem.getLocalName().equals("KeyName")) {
        throw new Exception
            ("Should be KeyName element: " + knElem.getLocalName());
    }
}
 
Example 10
Source File: XMLSignatureFactory.java    From openjdk-8-source with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns a <code>KeyInfoFactory</code> that creates <code>KeyInfo</code>
 * objects. The returned <code>KeyInfoFactory</code> has the same
 * mechanism type and provider as this <code>XMLSignatureFactory</code>.
 *
 * @return a <code>KeyInfoFactory</code>
 * @throws NoSuchMechanismException if a <code>KeyFactory</code>
 *    implementation with the same mechanism type and provider
 *    is not available
 */
public final KeyInfoFactory getKeyInfoFactory() {
    return KeyInfoFactory.getInstance(getMechanismType(), getProvider());
}
 
Example 11
Source File: XMLSignatureFactory.java    From hottub with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns a <code>KeyInfoFactory</code> that creates <code>KeyInfo</code>
 * objects. The returned <code>KeyInfoFactory</code> has the same
 * mechanism type and provider as this <code>XMLSignatureFactory</code>.
 *
 * @return a <code>KeyInfoFactory</code>
 * @throws NoSuchMechanismException if a <code>KeyFactory</code>
 *    implementation with the same mechanism type and provider
 *    is not available
 */
public final KeyInfoFactory getKeyInfoFactory() {
    return KeyInfoFactory.getInstance(getMechanismType(), getProvider());
}
 
Example 12
Source File: XMLSignatureFactory.java    From jdk8u-jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns a <code>KeyInfoFactory</code> that creates <code>KeyInfo</code>
 * objects. The returned <code>KeyInfoFactory</code> has the same
 * mechanism type and provider as this <code>XMLSignatureFactory</code>.
 *
 * @return a <code>KeyInfoFactory</code>
 * @throws NoSuchMechanismException if a <code>KeyFactory</code>
 *    implementation with the same mechanism type and provider
 *    is not available
 */
public final KeyInfoFactory getKeyInfoFactory() {
    return KeyInfoFactory.getInstance(getMechanismType(), getProvider());
}
 
Example 13
Source File: XMLSignatureFactory.java    From openjdk-jdk9 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns a <code>KeyInfoFactory</code> that creates <code>KeyInfo</code>
 * objects. The returned <code>KeyInfoFactory</code> has the same
 * mechanism type and provider as this <code>XMLSignatureFactory</code>.
 *
 * @return a <code>KeyInfoFactory</code>
 * @throws NoSuchMechanismException if a <code>KeyFactory</code>
 *    implementation with the same mechanism type and provider
 *    is not available
 */
public final KeyInfoFactory getKeyInfoFactory() {
    return KeyInfoFactory.getInstance(getMechanismType(), getProvider());
}
 
Example 14
Source File: XMLSignatureFactory.java    From openjdk-jdk8u with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns a <code>KeyInfoFactory</code> that creates <code>KeyInfo</code>
 * objects. The returned <code>KeyInfoFactory</code> has the same
 * mechanism type and provider as this <code>XMLSignatureFactory</code>.
 *
 * @return a <code>KeyInfoFactory</code>
 * @throws NoSuchMechanismException if a <code>KeyFactory</code>
 *    implementation with the same mechanism type and provider
 *    is not available
 */
public final KeyInfoFactory getKeyInfoFactory() {
    return KeyInfoFactory.getInstance(getMechanismType(), getProvider());
}
 
Example 15
Source File: XMLSignatureFactory.java    From JDKSourceCode1.8 with MIT License 2 votes vote down vote up
/**
 * Returns a <code>KeyInfoFactory</code> that creates <code>KeyInfo</code>
 * objects. The returned <code>KeyInfoFactory</code> has the same
 * mechanism type and provider as this <code>XMLSignatureFactory</code>.
 *
 * @return a <code>KeyInfoFactory</code>
 * @throws NoSuchMechanismException if a <code>KeyFactory</code>
 *    implementation with the same mechanism type and provider
 *    is not available
 */
public final KeyInfoFactory getKeyInfoFactory() {
    return KeyInfoFactory.getInstance(getMechanismType(), getProvider());
}
 
Example 16
Source File: XMLSignatureFactory.java    From jdk8u-dev-jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns a <code>KeyInfoFactory</code> that creates <code>KeyInfo</code>
 * objects. The returned <code>KeyInfoFactory</code> has the same
 * mechanism type and provider as this <code>XMLSignatureFactory</code>.
 *
 * @return a <code>KeyInfoFactory</code>
 * @throws NoSuchMechanismException if a <code>KeyFactory</code>
 *    implementation with the same mechanism type and provider
 *    is not available
 */
public final KeyInfoFactory getKeyInfoFactory() {
    return KeyInfoFactory.getInstance(getMechanismType(), getProvider());
}
 
Example 17
Source File: XMLSignatureFactory.java    From jdk8u60 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns a <code>KeyInfoFactory</code> that creates <code>KeyInfo</code>
 * objects. The returned <code>KeyInfoFactory</code> has the same
 * mechanism type and provider as this <code>XMLSignatureFactory</code>.
 *
 * @return a <code>KeyInfoFactory</code>
 * @throws NoSuchMechanismException if a <code>KeyFactory</code>
 *    implementation with the same mechanism type and provider
 *    is not available
 */
public final KeyInfoFactory getKeyInfoFactory() {
    return KeyInfoFactory.getInstance(getMechanismType(), getProvider());
}
 
Example 18
Source File: XMLSignatureFactory.java    From jdk8u_jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns a <code>KeyInfoFactory</code> that creates <code>KeyInfo</code>
 * objects. The returned <code>KeyInfoFactory</code> has the same
 * mechanism type and provider as this <code>XMLSignatureFactory</code>.
 *
 * @return a <code>KeyInfoFactory</code>
 * @throws NoSuchMechanismException if a <code>KeyFactory</code>
 *    implementation with the same mechanism type and provider
 *    is not available
 */
public final KeyInfoFactory getKeyInfoFactory() {
    return KeyInfoFactory.getInstance(getMechanismType(), getProvider());
}
 
Example 19
Source File: XMLSignatureFactory.java    From TencentKona-8 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns a <code>KeyInfoFactory</code> that creates <code>KeyInfo</code>
 * objects. The returned <code>KeyInfoFactory</code> has the same
 * mechanism type and provider as this <code>XMLSignatureFactory</code>.
 *
 * @return a <code>KeyInfoFactory</code>
 * @throws NoSuchMechanismException if a <code>KeyFactory</code>
 *    implementation with the same mechanism type and provider
 *    is not available
 */
public final KeyInfoFactory getKeyInfoFactory() {
    return KeyInfoFactory.getInstance(getMechanismType(), getProvider());
}
 
Example 20
Source File: XMLSignatureFactory.java    From dragonwell8_jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns a <code>KeyInfoFactory</code> that creates <code>KeyInfo</code>
 * objects. The returned <code>KeyInfoFactory</code> has the same
 * mechanism type and provider as this <code>XMLSignatureFactory</code>.
 *
 * @return a <code>KeyInfoFactory</code>
 * @throws NoSuchMechanismException if a <code>KeyFactory</code>
 *    implementation with the same mechanism type and provider
 *    is not available
 */
public final KeyInfoFactory getKeyInfoFactory() {
    return KeyInfoFactory.getInstance(getMechanismType(), getProvider());
}