Example usage for java.security.cert CertificateFactory generateCertificate

List of usage examples for java.security.cert CertificateFactory generateCertificate

Introduction

In this page you can find the example usage for java.security.cert CertificateFactory generateCertificate.

Prototype

public final Certificate generateCertificate(InputStream inStream) throws CertificateException 

Source Link

Document

Generates a certificate object and initializes it with the data read from the input stream inStream .

Usage

From source file:com.linkage.crm.csb.sign.CtSignature.java

/**
 * .//from   w  ww .  j  a v  a2s  . c o  m
 * 
 * @param originalText String 
 * @param signedText String 
 * @param pubKeyFile String 
 * @return boolean 
 */
public static boolean verify(String originalText, String signedText, String pubKeyFile) {
    try {
        CertificateFactory certificatefactory = CertificateFactory.getInstance("X.509");
        FileInputStream fin = new FileInputStream(pubKeyFile);
        X509Certificate certificate = (X509Certificate) certificatefactory.generateCertificate(fin);
        PublicKey pub = certificate.getPublicKey();
        Signature dsa = Signature.getInstance("SHA1withDSA");
        dsa.initVerify(pub);
        dsa.update(originalText.getBytes());
        return dsa.verify(HexUtils.fromHexString(signedText));
    } catch (Exception ex) {
        logger.error("errors appeared while trying to verify a signature", ex);
        return false;
    }
}

From source file:be.fedict.eid.dss.admin.portal.control.bean.RPBean.java

private static X509Certificate getCertificate(byte[] certificateBytes) throws CertificateException {

    CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
    return (X509Certificate) certificateFactory.generateCertificate(new ByteArrayInputStream(certificateBytes));
}

From source file:edu.ucsb.eucalyptus.keys.AbstractKeyStore.java

public static X509Certificate pemToX509(final String certPem)
        throws CertificateException, NoSuchProviderException {
    CertificateFactory certificatefactory = CertificateFactory.getInstance("X.509", KeyTool.PROVIDER);
    X509Certificate cert = (X509Certificate) certificatefactory
            .generateCertificate(new ByteArrayInputStream(certPem.getBytes()));
    return cert;//from  w w w .  j av  a 2  s.c o  m
}

From source file:cn.com.loopj.android.http.MySSLSocketFactory.java

/**
 * Gets a KeyStore containing the Certificate
 *
 * @param cert InputStream of the Certificate
 * @return KeyStore//from   www .ja  v  a 2  s .co m
 */
public static KeyStore getKeystoreOfCA(InputStream cert) {

    // Load CAs from an InputStream
    InputStream caInput = null;
    Certificate ca = null;
    try {
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        caInput = new BufferedInputStream(cert);
        ca = cf.generateCertificate(caInput);
    } catch (CertificateException e1) {
        e1.printStackTrace();
    } finally {
        try {
            if (caInput != null) {
                caInput.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    // Create a KeyStore containing our trusted CAs
    String keyStoreType = KeyStore.getDefaultType();
    KeyStore keyStore = null;
    try {
        keyStore = KeyStore.getInstance(keyStoreType);
        keyStore.load(null, null);
        keyStore.setCertificateEntry("ca", ca);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return keyStore;
}

From source file:eidassaml.starterkit.Utils.java

/**
 * /*from   w  w w .java2  s.com*/
 * @param is
 * @return
 * @throws IOException
 * @throws CertificateException
 */
public static X509Certificate readX509Certificate(InputStream is) throws IOException, CertificateException {
    CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
    return (X509Certificate) certFactory.generateCertificate(is);
}

From source file:net.link.util.test.pkix.PkiTestUtils.java

public static X509Certificate loadCertificate(InputStream inputStream) throws CertificateException {

    CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
    return (X509Certificate) certificateFactory.generateCertificate(inputStream);
}

From source file:me.xiaopan.android.gohttp.httpclient.MySSLSocketFactory.java

/**
 * Gets a KeyStore containing the Certificate
 *
 * @param cert InputStream of the Certificate
 * @return KeyStore/*from   w  w  w .j ava 2  s.  c om*/
 */
public static KeyStore getKeystoreOfCA(InputStream cert) {

    // Load CAs from an InputStream
    InputStream caInput = null;
    Certificate ca = null;
    try {
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        caInput = new BufferedInputStream(cert);
        ca = (Certificate) cf.generateCertificate(caInput);
    } catch (CertificateException e1) {
        e1.printStackTrace();
    } finally {
        try {
            caInput.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    // Create a KeyStore containing our trusted CAs
    String keyStoreType = KeyStore.getDefaultType();
    KeyStore keyStore = null;
    try {
        keyStore = KeyStore.getInstance(keyStoreType);
        keyStore.load(null, null);
        keyStore.setCertificateEntry("ca", (Certificate) ca);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return keyStore;
}

From source file:com.shalzz.attendance.wrapper.MySSLSocketFactory.java

/**
 * Gets a KeyStore containing the Certificate
 * //from  w w w. java  2 s .  com
 * @param cert InputStream of the Certificate
 * @return KeyStore
 */
public static KeyStore getKeystoreOfCA(InputStream cert) {

    // Load CAs from an InputStream
    InputStream caInput = null;
    Certificate ca = null;
    try {
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        caInput = new BufferedInputStream(cert);
        ca = cf.generateCertificate(caInput);
    } catch (CertificateException e1) {
        e1.printStackTrace();
    } finally {
        try {
            caInput.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    // Create a KeyStore containing our trusted CAs
    String keyStoreType = KeyStore.getDefaultType();
    KeyStore keyStore = null;
    try {
        keyStore = KeyStore.getInstance(keyStoreType);
        keyStore.load(null, null);
        keyStore.setCertificateEntry("ca", ca);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return keyStore;
}

From source file:kr.co.exsoft.eframework.util.LicenseUtil.java

/**
 * /* w  ww  .  j  av a 2 s. c o m*/
 * <pre> 
 * 1.  :  ??   WAS
 * 2.  :
 * </pre>
 * @Method Name : decipherLicenseKeyWeb
 * @param licenseKey
 * @return String
 * @throws Exception
 */
public static String decipherLicenseKeyWeb(String licenseKey) throws Exception {

    String ret = null;

    if (StringUtils.isNotBlank(licenseKey)) {

        // URLDecoder - ? ?   
        String certName = URLDecoder.decode(
                LicenseUtil.class.getResource("/").getPath() + "kr/co/exsoft/eframework/cert/exsoft.cer",
                "utf-8");

        //  WAS  
        if (certName.indexOf("WEB-INF/") != -1) {
            certName = certName.replace("WEB-INF", "WEB-INF/");
        }

        FileInputStream certfis = null;

        try {
            certfis = new FileInputStream(certName);
        } catch (Exception e) {
            // JBOSS?  Jboss system property?   .
            // Jboss system  ? standalone.xml ? 
            /*<system-properties>
               <property name="org.apache.catalina.connector.URI_ENCODING" value="UTF-8" />
               <property name="org.apache.catalina.connector.USE_BODY_ENCODING_FOR_QUERY_STRING" value="true" />
               <property name="exsoft.license.cert.path" value="D:/jboss-eap-6.3/standalone/deployments/EDMS3.0.war/WEB-INF/classes" /> 
            </system-properties>*/
            // Jboss exception ?  WAS System property    

            certName = URLDecoder.decode(
                    System.getProperty("exsoft.license.cert.path") + "/kr/co/exsoft/eframework/cert/exsoft.cer",
                    "utf-8");

            try {
                certfis = new FileInputStream(certName);
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }

        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        Certificate cert = cf.generateCertificate(certfis);

        PublicKey key = cert.getPublicKey();

        // ??  .
        ret = unspell(licenseKey, key);
    }

    return ret;
}

From source file:Main.java

/**
 *
 * @param f//from   w w  w. jav a 2  s. co  m
 * @throws Exception
 */
private static X509Certificate readCertificate(File f) throws CertificateException, IOException {
    CertificateFactory cf = CertificateFactory.getInstance("X.509");

    // Use BufferedInputStream (which supports mark and reset) so that each
    // generateCertificate call consumes one certificate.
    BufferedInputStream in = new BufferedInputStream(new FileInputStream(f));
    X509Certificate cert = (X509Certificate) cf.generateCertificate(in);
    in.close();
    return cert;
}