當前位置: 首頁>>代碼示例>>Java>>正文


Java CertificateFactory.generateCertificate方法代碼示例

本文整理匯總了Java中java.security.cert.CertificateFactory.generateCertificate方法的典型用法代碼示例。如果您正苦於以下問題:Java CertificateFactory.generateCertificate方法的具體用法?Java CertificateFactory.generateCertificate怎麽用?Java CertificateFactory.generateCertificate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.security.cert.CertificateFactory的用法示例。


在下文中一共展示了CertificateFactory.generateCertificate方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getUserCertificate1

import java.security.cert.CertificateFactory; //導入方法依賴的package包/類
private static X509Certificate getUserCertificate1() throws Exception {
    // this certificate includes an extension
    String sCert =
        "-----BEGIN CERTIFICATE-----\n"
      + "MIIBfzCCASmgAwIBAgIQWFSKzCWO2ptOAc2F3MKZSzANBgkqhkiG9w0BAQQFADAa\n"
      + "MRgwFgYDVQQDEw9Sb290Q2VydGlmaWNhdGUwHhcNMDExMDE5MTMwNzQxWhcNMzkx\n"
      + "MjMxMjM1OTU5WjAaMRgwFgYDVQQDEw9Vc2VyQ2VydGlmaWNhdGUwXDANBgkqhkiG\n"
      + "9w0BAQEFAANLADBIAkEA24gypa2YFGZHKznEWWbqIWNVXCM35W7RwJwhGpNsuBCj\n"
      + "NT6KEo66F+OOMgZmb0KrEZHBJASJ3n4Cqbt4aHm/2wIDAQABo0swSTBHBgNVHQEE\n"
      + "QDA+gBBch+eYzOPgVRbMq5vGpVWooRgwFjEUMBIGA1UEAxMLUm9vdCBBZ2VuY3mC\n"
      + "EMlg/HS1KKqSRcg8a30Za7EwDQYJKoZIhvcNAQEEBQADQQCYBIHBqQQJePi5Hzfo\n"
      + "CxeUaYlXmvbxVNkxM65Pplsj3h4ntfZaynmlhahH3YsnnA8wk6xPt04LjSId12RB\n"
      + "PeuO\n"
      + "-----END CERTIFICATE-----";
    CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
    ByteArrayInputStream bytes = new ByteArrayInputStream(sCert.getBytes());
    return (X509Certificate)certFactory.generateCertificate(bytes);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:NoExtensions.java

示例2: runTest

import java.security.cert.CertificateFactory; //導入方法依賴的package包/類
/**
 * Test logic (environment has set up)
 */
private void runTest() throws FileNotFoundException, CertificateException,
        KeyStoreException, IOException, NoSuchAlgorithmException {
    Certificate cert;
    CertificateFactory cf;
    try (FileInputStream fi = new FileInputStream(CERT_PATH)) {
        cf = CertificateFactory.getInstance("X.509");
        cert = cf.generateCertificate(fi);
        KeyStore ks = KeyStore.getInstance(
                Utils.KeyStoreType.pkcs12.name());
        ks.load(null, null);
        ks.setCertificateEntry(ALIAS, cert);
        Utils.saveKeyStore(ks, KEYSTORE_PATH, PASSWORD);
        ks = Utils.loadKeyStore(KEYSTORE_PATH, Utils.KeyStoreType.pkcs12,
                PASSWORD);
        final Certificate ksCert = ks.getCertificate(ALIAS);
        if (!ksCert.equals(cert)) {
            err.println("Orig cert: " + cert.toString());
            err.println("Cert from keystore: " + ksCert.toString());
            throw new RuntimeException("Certificates don't match");
        }
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:26,代碼來源:StoreTrustedCertAPITest.java

示例3: getUserCertificate2

import java.security.cert.CertificateFactory; //導入方法依賴的package包/類
private static X509Certificate getUserCertificate2() throws Exception {
    // this certificate does not include any extensions
    String sCert =
        "-----BEGIN CERTIFICATE-----\n"
      + "MIIBMjCB3aADAgECAhB6225ckZVssEukPuvk1U1PMA0GCSqGSIb3DQEBBAUAMBox\n"
      + "GDAWBgNVBAMTD1Jvb3RDZXJ0aWZpY2F0ZTAeFw0wMTEwMTkxNjA5NTZaFw0wMjEw\n"
      + "MTkyMjA5NTZaMBsxGTAXBgNVBAMTEFVzZXJDZXJ0aWZpY2F0ZTIwXDANBgkqhkiG\n"
      + "9w0BAQEFAANLADBIAkEAzicGiW9aUlUoQIZnLy1l8MMV5OvA+4VJ4T/xo/PpN8Oq\n"
      + "WgZVGKeEp6JCzMlXEJk3TGLfpXL4Ytw+Ldhv0QPhLwIDAnMpMA0GCSqGSIb3DQEB\n"
      + "BAUAA0EAQmj9SFHEx66JyAps3ew4pcSS3QvfVZ/6qsNUYCG75rFGcTUPHcXKql9y\n"
      + "qBT83iNLJ//krjw5Ju0WRPg/buHSww==\n"
      + "-----END CERTIFICATE-----";
    CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
    ByteArrayInputStream bytes = new ByteArrayInputStream(sCert.getBytes());
    return (X509Certificate)certFactory.generateCertificate(bytes);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:NoExtensions.java

示例4: isDebuggable

import java.security.cert.CertificateFactory; //導入方法依賴的package包/類
/**
 * 檢測當前應用是否是Debug版本
 *
 * @param ctx
 * @return
 */
public static boolean isDebuggable(Context ctx) {
    boolean debuggable = false;
    try {
        PackageInfo pinfo = ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), PackageManager.GET_SIGNATURES);
        Signature signatures[] = pinfo.signatures;
        for (Signature signature : signatures) {
            CertificateFactory cf = CertificateFactory.getInstance("X.509");
            ByteArrayInputStream stream = new ByteArrayInputStream(signature.toByteArray());
            X509Certificate cert = (X509Certificate) cf
                    .generateCertificate(stream);
            debuggable = cert.getSubjectX500Principal().equals(DEBUG_DN);
            if (debuggable)
                break;
        }

    } catch (NameNotFoundException | CertificateException e) {
    }
    return debuggable;
}
 
開發者ID:huashengzzz,項目名稱:SmartChart,代碼行數:26,代碼來源:AppUtils.java

示例5: loadCert

import java.security.cert.CertificateFactory; //導入方法依賴的package包/類
private X509Certificate loadCert(Session session, long oHandle)
            throws PKCS11Exception, CertificateException {

    CK_ATTRIBUTE[] attrs = new CK_ATTRIBUTE[]
                    { new CK_ATTRIBUTE(CKA_VALUE) };
    token.p11.C_GetAttributeValue(session.id(), oHandle, attrs);

    byte[] bytes = attrs[0].getByteArray();
    if (bytes == null) {
        throw new CertificateException
                    ("unexpectedly retrieved null byte array");
    }
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    return (X509Certificate)cf.generateCertificate
                    (new ByteArrayInputStream(bytes));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:P11KeyStore.java

示例6: createX509CertificateFromFile

import java.security.cert.CertificateFactory; //導入方法依賴的package包/類
private static X509Certificate createX509CertificateFromFile(
  	final String certificateFileName) throws IOException, CertificateException 
  {
      // Load an X509 certificate from the specified certificate file name
final File file = new java.io.File(certificateFileName);
if (!file.isFile()) {
	throw new IOException(
		String.format("The certificate file %s doesn't exist.", certificateFileName));
}
   	final CertificateFactory certificateFactoryX509 = CertificateFactory.getInstance("X.509");
   	final InputStream inputStream = new FileInputStream(file);
      final X509Certificate certificate = (X509Certificate) certificateFactoryX509.generateCertificate(inputStream);
      inputStream.close();
      
      return certificate;
  }
 
開發者ID:PacktPublishing,項目名稱:MQTT-Essentials-A-Lightweight-IoT-Protocol,代碼行數:17,代碼來源:SecurityHelper.java

示例7: addCertificate

import java.security.cert.CertificateFactory; //導入方法依賴的package包/類
private SSLSocketFactory addCertificate(InputStream inputStream) throws CertificateException, NoSuchAlgorithmException, IOException, KeyStoreException, KeyManagementException {
    // loading CAs from an InputStream
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    Certificate ca;
    try {
        ca = cf.generateCertificate(inputStream);
    } finally {
        inputStream.close();
    }

    // creating a KeyStore containing our trusted CAs
    String keyStoreType = KeyStore.getDefaultType();
    KeyStore keyStore = KeyStore.getInstance(keyStoreType);
    keyStore.load(null, null);
    keyStore.setCertificateEntry("ca", ca);

    // creating a TrustManager that trusts the CAs in our KeyStore
    String tmfAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
    TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlgorithm);
    tmf.init(keyStore);

    // creating an SSLSocketFactory that uses our TrustManager
    SSLContext sslContext = SSLContext.getInstance("TLS");
    sslContext.init(null, tmf.getTrustManagers(), null);

    return sslContext.getSocketFactory();
}
 
開發者ID:sinhaDroid,項目名稱:BlogBookApp,代碼行數:28,代碼來源:MyWebService.java

示例8: WriteP12Test

import java.security.cert.CertificateFactory; //導入方法依賴的package包/類
WriteP12Test() throws CertificateException {
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    caCert = cf.generateCertificate(new ByteArrayInputStream(CA_CERT_STR
            .getBytes()));
    testLeadCert = cf.generateCertificate(new ByteArrayInputStream(
            LEAD_CERT.getBytes()));
    testerCert = cf.generateCertificate(new ByteArrayInputStream(END_CERT
            .getBytes()));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:10,代碼來源:WriteP12Test.java

示例9: getCertificate

import java.security.cert.CertificateFactory; //導入方法依賴的package包/類
public static Certificate getCertificate(String certificatePath) throws Exception {
    CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
    FileInputStream in = new FileInputStream(certificatePath);
    Certificate certificate = certificateFactory.generateCertificate(in);
    in.close();
    return certificate;
}
 
開發者ID:didi,項目名稱:VirtualAPK,代碼行數:8,代碼來源:ZipVerifyUtil.java

示例10: readCert

import java.security.cert.CertificateFactory; //導入方法依賴的package包/類
private static Certificate readCert(DataInputStream in)
    throws IOException, CertificateException, NoSuchAlgorithmException
{
    String type = in.readUTF();
    int len = in.readInt();
    byte[] encoded = new byte[len];
    in.read(encoded);
    CertificateFactory factory = CertificateFactory.getInstance(type);
    return factory.generateCertificate(new ByteArrayInputStream(encoded));
}
 
開發者ID:uhuru-mobile,項目名稱:mobile-store,代碼行數:11,代碼來源:JKS.java

示例11: testCheckExpired

import java.security.cert.CertificateFactory; //導入方法依賴的package包/類
@Test(expected = CertificateException.class)
public void testCheckExpired() throws Exception {
    final CertificateStoreX509TrustManager m = new CertificateStoreX509TrustManager(new TrustManagerHostnameCallback() {
        @Override
        public String getTarget() {
            return "cyberduck.ch";
        }
    }, new DefaultCertificateStore());
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    X509Certificate cert = (X509Certificate) cf.generateCertificate(
            new FileInputStream("src/test/resources//OXxlRDVcWqdPEvFm.cer")
    );
    m.checkServerTrusted(new X509Certificate[]{cert}, "RSA");
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:15,代碼來源:CertificateStoreX509TrustManagerTest.java

示例12: readCert

import java.security.cert.CertificateFactory; //導入方法依賴的package包/類
private X509Certificate readCert(String filename) throws IOException, CertificateException {
    String fullPath = this.certDirectory + "/" + filename;
    FileInputStream fis = new FileInputStream(fullPath);
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    X509Certificate cert = (X509Certificate) cf.generateCertificate(fis);
    fis.close();
    return cert;
}
 
開發者ID:e-gov,項目名稱:TARA-Server,代碼行數:9,代碼來源:AuthenticationServiceImpl.java

示例13: loadX509Cert

import java.security.cert.CertificateFactory; //導入方法依賴的package包/類
public static X509Certificate loadX509Cert(String fileName) throws CertificateException, IOException {
    CertificateFactory cf = CertificateFactory.getInstance("X.509");

    InputStream in = SslUtil.class.getClassLoader().getResourceAsStream("certs/" + fileName);
    try {
        return (X509Certificate) cf.generateCertificate(in);
    } finally {
        in.close();
    }
}
 
開發者ID:venus-boot,項目名稱:saluki,代碼行數:11,代碼來源:SslUtil.java

示例14: invoke

import java.security.cert.CertificateFactory; //導入方法依賴的package包/類
public void invoke(Request request, Response response)
    throws IOException, ServletException {

    /* mod_header converts the '\n' into ' ' so we have to rebuild the client certificate */
    String strcert0 = mygetHeader(request, "ssl_client_cert");
    if (strcert0 != null && strcert0.length()>28) {
        String strcert1 = strcert0.replace(' ', '\n');
        String strcert2 = strcert1.substring(28, strcert1.length()-26);
        String strcert3 = new String("-----BEGIN CERTIFICATE-----\n");
        String strcert4 = strcert3.concat(strcert2);
        String strcerts = strcert4.concat("\n-----END CERTIFICATE-----\n");
        // ByteArrayInputStream bais = new ByteArrayInputStream(strcerts.getBytes("UTF-8"));
        ByteArrayInputStream bais = new ByteArrayInputStream(strcerts.getBytes());
        X509Certificate jsseCerts[] = null;
        try {
            CertificateFactory cf = CertificateFactory.getInstance("X.509");
            X509Certificate cert = (X509Certificate) cf.generateCertificate(bais);
            jsseCerts = new X509Certificate[1];
            jsseCerts[0] = cert;
        } catch (java.security.cert.CertificateException e) {
            System.out.println("SSLValve failed " + strcerts);
            System.out.println("SSLValve failed " + e);
        }
        request.setAttribute("javax.servlet.request.X509Certificate", jsseCerts);
    }
    strcert0 = mygetHeader(request, "ssl_cipher");
    if (strcert0 != null) {
        request.setAttribute("javax.servlet.request.cipher_suite", strcert0);
    }
    strcert0 = mygetHeader(request, "ssl_session_id");
    if (strcert0 != null) {
        request.setAttribute("javax.servlet.request.ssl_session", strcert0);
    }
    strcert0 = mygetHeader(request, "ssl_cipher_usekeysize");
    if (strcert0 != null) {
        request.setAttribute("javax.servlet.request.key_size", strcert0);
    }
    getNext().invoke(request, response);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:40,代碼來源:SSLValve.java

示例15: getCertificate

import java.security.cert.CertificateFactory; //導入方法依賴的package包/類
/**
 * 獲取CA證書信息
 * @param cafile CA證書文件
 * @return Certificate
 * @throws CertificateException
 * @throws IOException
 */
public static Certificate getCertificate(File cafile)
		throws CertificateException, IOException {
	CertificateFactory cf = CertificateFactory.getInstance("X.509");
	FileInputStream in = new FileInputStream(cafile);
	Certificate cert = cf.generateCertificate(in);
	in.close();
	return cert;
}
 
開發者ID:ywtnhm,項目名稱:pay-xxpay-master,代碼行數:16,代碼來源:HttpClientUtil.java


注:本文中的java.security.cert.CertificateFactory.generateCertificate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。