Search in sources :

Example 6 with KeyException

use of java.security.KeyException in project robovm by robovm.

the class KeyExceptionTest method testKeyException03.

/**
     * Test for <code>KeyException(String)</code> constructor Assertion:
     * constructs KeyException when <code>msg</code> is null
     */
public void testKeyException03() {
    String msg = null;
    KeyException tE = new KeyException(msg);
    assertNull("getMessage() must return null.", tE.getMessage());
    assertNull("getCause() must return null", tE.getCause());
}
Also used : KeyException(java.security.KeyException)

Example 7 with KeyException

use of java.security.KeyException in project robovm by robovm.

the class KeyExceptionTest method testKeyException07.

/**
     * Test for <code>KeyException(String, Throwable)</code> constructor
     * Assertion: constructs KeyException when <code>cause</code> is null
     * <code>msg</code> is not null
     */
public void testKeyException07() {
    KeyException tE;
    for (int i = 0; i < msgs.length; i++) {
        tE = new KeyException(msgs[i], null);
        assertEquals("getMessage() must return: ".concat(msgs[i]), tE.getMessage(), msgs[i]);
        assertNull("getCause() must return null", tE.getCause());
    }
}
Also used : KeyException(java.security.KeyException)

Example 8 with KeyException

use of java.security.KeyException in project poi by apache.

the class KeyInfoSignatureFacet method postSign.

@Override
public void postSign(Document document) throws MarshalException {
    LOG.log(POILogger.DEBUG, "postSign");
    NodeList nl = document.getElementsByTagNameNS(XML_DIGSIG_NS, "Object");
    /*
         * Make sure we insert right after the ds:SignatureValue element, just
         * before the first ds:Object element.
         */
    Node nextSibling = (nl.getLength() == 0) ? null : nl.item(0);
    /*
         * Construct the ds:KeyInfo element using JSR 105.
         */
    KeyInfoFactory keyInfoFactory = signatureConfig.getKeyInfoFactory();
    List<Object> x509DataObjects = new ArrayList<Object>();
    X509Certificate signingCertificate = signatureConfig.getSigningCertificateChain().get(0);
    List<XMLStructure> keyInfoContent = new ArrayList<XMLStructure>();
    if (signatureConfig.isIncludeKeyValue()) {
        KeyValue keyValue;
        try {
            keyValue = keyInfoFactory.newKeyValue(signingCertificate.getPublicKey());
        } catch (KeyException e) {
            throw new RuntimeException("key exception: " + e.getMessage(), e);
        }
        keyInfoContent.add(keyValue);
    }
    if (signatureConfig.isIncludeIssuerSerial()) {
        x509DataObjects.add(keyInfoFactory.newX509IssuerSerial(signingCertificate.getIssuerX500Principal().toString(), signingCertificate.getSerialNumber()));
    }
    if (signatureConfig.isIncludeEntireCertificateChain()) {
        x509DataObjects.addAll(signatureConfig.getSigningCertificateChain());
    } else {
        x509DataObjects.add(signingCertificate);
    }
    if (!x509DataObjects.isEmpty()) {
        X509Data x509Data = keyInfoFactory.newX509Data(x509DataObjects);
        keyInfoContent.add(x509Data);
    }
    KeyInfo keyInfo = keyInfoFactory.newKeyInfo(keyInfoContent);
    DOMKeyInfo domKeyInfo = (DOMKeyInfo) keyInfo;
    Key key = new Key() {

        private static final long serialVersionUID = 1L;

        public String getAlgorithm() {
            return null;
        }

        public byte[] getEncoded() {
            return null;
        }

        public String getFormat() {
            return null;
        }
    };
    Element n = document.getDocumentElement();
    DOMSignContext domSignContext = (nextSibling == null) ? new DOMSignContext(key, n) : new DOMSignContext(key, n, nextSibling);
    for (Map.Entry<String, String> me : signatureConfig.getNamespacePrefixes().entrySet()) {
        domSignContext.putNamespacePrefix(me.getKey(), me.getValue());
    }
    DOMStructure domStructure = new DOMStructure(n);
    domKeyInfo.marshal(domStructure, domSignContext);
    // move keyinfo into the right place
    if (nextSibling != null) {
        NodeList kiNl = document.getElementsByTagNameNS(XML_DIGSIG_NS, "KeyInfo");
        if (kiNl.getLength() != 1) {
            throw new RuntimeException("KeyInfo wasn't set");
        }
        nextSibling.getParentNode().insertBefore(kiNl.item(0), nextSibling);
    }
}
Also used : KeyValue(javax.xml.crypto.dsig.keyinfo.KeyValue) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) XMLStructure(javax.xml.crypto.XMLStructure) X509Data(javax.xml.crypto.dsig.keyinfo.X509Data) X509Certificate(java.security.cert.X509Certificate) KeyException(java.security.KeyException) KeyInfoFactory(javax.xml.crypto.dsig.keyinfo.KeyInfoFactory) KeyInfo(javax.xml.crypto.dsig.keyinfo.KeyInfo) DOMKeyInfo(org.apache.jcp.xml.dsig.internal.dom.DOMKeyInfo) DOMSignContext(javax.xml.crypto.dsig.dom.DOMSignContext) DOMKeyInfo(org.apache.jcp.xml.dsig.internal.dom.DOMKeyInfo) DOMStructure(javax.xml.crypto.dom.DOMStructure) Map(java.util.Map) Key(java.security.Key)

Example 9 with KeyException

use of java.security.KeyException in project jdk8u_jdk by JetBrains.

the class RSAPublicKey method getPublicExponent.

/**
     * Returns the public exponent.
     */
public BigInteger getPublicExponent() {
    if (exponent == null) {
        try {
            publicKeyBlob = getPublicKeyBlob(handles.hCryptKey);
            exponent = new BigInteger(1, getExponent(publicKeyBlob));
        } catch (KeyException e) {
            throw new ProviderException(e);
        }
    }
    return exponent;
}
Also used : ProviderException(java.security.ProviderException) BigInteger(java.math.BigInteger) KeyException(java.security.KeyException)

Example 10 with KeyException

use of java.security.KeyException in project jdk8u_jdk by JetBrains.

the class RSAPublicKey method getModulus.

/**
     * Returns the modulus.
     */
public BigInteger getModulus() {
    if (modulus == null) {
        try {
            publicKeyBlob = getPublicKeyBlob(handles.hCryptKey);
            modulus = new BigInteger(1, getModulus(publicKeyBlob));
        } catch (KeyException e) {
            throw new ProviderException(e);
        }
    }
    return modulus;
}
Also used : ProviderException(java.security.ProviderException) BigInteger(java.math.BigInteger) KeyException(java.security.KeyException)

Aggregations

KeyException (java.security.KeyException)21 IOException (java.io.IOException)7 Key (java.security.Key)4 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3 CancellationException (java.util.concurrent.CancellationException)3 ArchiveInputStream (org.apache.commons.compress.archivers.ArchiveInputStream)3 TarArchiveInputStream (org.apache.commons.compress.archivers.tar.TarArchiveInputStream)3 ZipArchiveInputStream (org.apache.commons.compress.archivers.zip.ZipArchiveInputStream)3 CountingInputStream (org.apache.commons.compress.utils.CountingInputStream)3 BufferedInputStream (java.io.BufferedInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 InputStream (java.io.InputStream)2 BigInteger (java.math.BigInteger)2 MessageDigest (java.security.MessageDigest)2 ProviderException (java.security.ProviderException)2 Matcher (java.util.regex.Matcher)2 SecretKeySpec (javax.crypto.spec.SecretKeySpec)2 BZip2CompressorInputStream (org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream)2 GzipCompressorInputStream (org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream)2