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


Java CertificateFactory類代碼示例

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


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

示例1: 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:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:17,代碼來源:NoExtensions.java

示例2: getCertificateFromStream

import java.security.cert.CertificateFactory; //導入依賴的package包/類
/**
 * Generate Collection of Certificate from Input Stream
 *
 * @param stream InputStream of Certificate data
 * @return Collection<X509Certificate>
 * @throws PayPalRESTException
 */
@SuppressWarnings("unchecked")
public static Collection<X509Certificate> getCertificateFromStream(InputStream stream) throws PayPalRESTException {
	if (stream == null) {
		throw new PayPalRESTException("Certificate Not Found");
	}
	Collection<X509Certificate> certs = null;
	try {
		// Create a Certificate Factory
		CertificateFactory cf = CertificateFactory.getInstance("X.509");

		// Read the Trust Certs
		certs = (Collection<X509Certificate>) cf.generateCertificates(stream);
	} catch (CertificateException ex) {
		throw new PayPalRESTException(ex);
	}
	return certs;
}
 
開發者ID:funtl,項目名稱:framework,代碼行數:25,代碼來源:SSLUtil.java

示例3: main

import java.security.cert.CertificateFactory; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
    if (args.length == 0) {
        System.out.println("Usage: java BlacklistedCertsConverter SHA-256" +
                " < blacklisted.certs.pem > blacklisted.certs");
        System.exit(1);
    }
    String mdAlg = args[0];
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    Collection<? extends Certificate> certs
            = cf.generateCertificates(System.in);
    System.out.println("Algorithm=" + mdAlg);
    for (Certificate cert: certs) {
        System.out.println(
                getCertificateFingerPrint(mdAlg, (X509Certificate)cert));
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:17,代碼來源:BlacklistedCertsConverter.java

示例4: getKeyFromConfigServer

import java.security.cert.CertificateFactory; //導入依賴的package包/類
private String getKeyFromConfigServer(RestTemplate keyUriRestTemplate) throws CertificateException {
    // Load available UAA servers
    discoveryClient.getServices();
    HttpEntity<Void> request = new HttpEntity<Void>(new HttpHeaders());
    String content = keyUriRestTemplate
        .exchange("http://config/api/token_key", HttpMethod.GET, request, String.class).getBody();

    if (StringUtils.isBlank(content)) {
        throw new CertificateException("Received empty certificate from config.");
    }

    InputStream fin = new ByteArrayInputStream(content.getBytes());

    CertificateFactory f = CertificateFactory.getInstance(Constants.CERTIFICATE);
    X509Certificate certificate = (X509Certificate)f.generateCertificate(fin);
    PublicKey pk = certificate.getPublicKey();
    return String.format(Constants.PUBLIC_KEY, new String(Base64.encode(pk.getEncoded())));
}
 
開發者ID:xm-online,項目名稱:xm-ms-dashboard,代碼行數:19,代碼來源:MicroserviceSecurityConfiguration.java

示例5: readCertificateList

import java.security.cert.CertificateFactory; //導入依賴的package包/類
private List<Certificate> readCertificateList(BufferedSource source) throws IOException {
  int length = readInt(source);
  if (length == -1) return Collections.emptyList(); // OkHttp v1.2 used -1 to indicate null.

  try {
    CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
    List<Certificate> result = new ArrayList<>(length);
    for (int i = 0; i < length; i++) {
      String line = source.readUtf8LineStrict();
      Buffer bytes = new Buffer();
      bytes.write(ByteString.decodeBase64(line));
      result.add(certificateFactory.generateCertificate(bytes.inputStream()));
    }
    return result;
  } catch (CertificateException e) {
    throw new IOException(e.getMessage());
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:19,代碼來源:Cache.java

示例6: testCreateCRLException

import java.security.cert.CertificateFactory; //導入依賴的package包/類
@Test
public void testCreateCRLException() {
  String crlfile = strFilePath + "/ssl/server.p12";
  boolean validAssert = true;
  try {
    new MockUp<CertificateFactory>() {
      @Mock
      public final CertificateFactory getInstance(String type) throws CertificateException {
        throw new CertificateException();
      }
    };

    KeyStoreUtil.createCRL(crlfile);
  } catch (Exception e) {
    validAssert = false;
  }
  Assert.assertFalse(validAssert);
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:19,代碼來源:KeyStoreUtilTest.java

示例7: 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:SunburstApps,項目名稱:OpenJSharp,代碼行數:17,代碼來源:P11KeyStore.java

示例8: getX509Certificate

import java.security.cert.CertificateFactory; //導入依賴的package包/類
/**
 * Method getX509Certificate
 *
 * @return the x509 certificate
 * @throws XMLSecurityException
 */
public X509Certificate getX509Certificate() throws XMLSecurityException {
    try {
        byte certbytes[] = this.getCertificateBytes();
        CertificateFactory certFact =
            CertificateFactory.getInstance(XMLX509Certificate.JCA_CERT_ID);
        X509Certificate cert =
            (X509Certificate) certFact.generateCertificate(
                new ByteArrayInputStream(certbytes)
            );

        if (cert != null) {
            return cert;
        }

        return null;
    } catch (CertificateException ex) {
        throw new XMLSecurityException("empty", ex);
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:26,代碼來源:XMLX509Certificate.java

示例9: test

import java.security.cert.CertificateFactory; //導入依賴的package包/類
static void test(String... files) throws Exception {
    try (FileOutputStream fout = new FileOutputStream(OUTFILE)) {
        String here = System.getProperty("test.src", "");
        for (String file: files) {
            Files.copy(Paths.get(here, file), fout);
        }
    }
    try (FileInputStream fin = new FileInputStream(OUTFILE)) {
        System.out.println("Testing " + Arrays.toString(files) + "...");
        if (CertificateFactory.getInstance("X509")
                .generateCertificates(fin)
                .size() != files.length) {
            throw new Exception("Not same number");
        }
    }
    Files.delete(Paths.get(OUTFILE));
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:18,代碼來源:OpenSSLCert.java

示例10: 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

示例11: PKCS12KeyStoreSpi

import java.security.cert.CertificateFactory; //導入依賴的package包/類
public PKCS12KeyStoreSpi(
    Provider provider,
    ASN1ObjectIdentifier keyAlgorithm,
    ASN1ObjectIdentifier certAlgorithm)
{
    this.keyAlgorithm = keyAlgorithm;
    this.certAlgorithm = certAlgorithm;

    try
    {
        if (provider != null)
        {
            certFact = CertificateFactory.getInstance("X.509", provider);
        }
        else
        {
            certFact = CertificateFactory.getInstance("X.509");
        }
    }
    catch (Exception e)
    {
        throw new IllegalArgumentException("can't create cert factory - " + e.toString());
    }
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:25,代碼來源:PKCS12KeyStoreSpi.java

示例12: parseObject

import java.security.cert.CertificateFactory; //導入依賴的package包/類
/**
 * Reads in a X509Certificate.
 *
 * @return the X509Certificate
 * @throws IOException if an I/O error occured
 */
public Object parseObject(PemObject obj)
    throws IOException
{
    ByteArrayInputStream bIn = new ByteArrayInputStream(obj.getContent());

    try
    {
        CertificateFactory certFact
            = CertificateFactory.getInstance("X.509", provider);

        return certFact.generateCertificate(bIn);
    }
    catch (Exception e)
    {
        throw new PEMException("problem parsing cert: " + e.toString(), e);
    }
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:24,代碼來源:PEMReader.java

示例13: test_create_signature_x509_crt_crl

import java.security.cert.CertificateFactory; //導入依賴的package包/類
static void test_create_signature_x509_crt_crl() throws Exception {
    System.out.println("* Generating signature-x509-crt-crl.xml");
    List<Object> xds = new ArrayList<>();
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    xds.add(signingCert);
    FileInputStream fis = new FileInputStream(CRL);
    X509CRL crl = (X509CRL) cf.generateCRL(fis);
    fis.close();
    xds.add(crl);
    KeyInfo crt_crl = kifac.newKeyInfo(Collections.singletonList
        (kifac.newX509Data(xds)));

    test_create_signature_external(dsaSha1, crt_crl, signingKey,
        new X509KeySelector(ks), false);
    System.out.println();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:GenerationTests.java

示例14: getKeyFromAuthorizationServer

import java.security.cert.CertificateFactory; //導入依賴的package包/類
private String getKeyFromAuthorizationServer(RestTemplate keyUriRestTemplate) throws CertificateException {
    // Load available UAA servers
    discoveryClient.getServices();
    HttpEntity<Void> request = new HttpEntity<Void>(new HttpHeaders());
    String content = keyUriRestTemplate
        .exchange("http://config/api/token_key", HttpMethod.GET, request, String.class).getBody();

    if (StringUtils.isBlank(content)) {
        throw new CertificateException("Received empty certificate from config.");
    }

    InputStream fin = new ByteArrayInputStream(content.getBytes());

    CertificateFactory f = CertificateFactory.getInstance(Constants.CERTIFICATE);
    X509Certificate certificate = (X509Certificate)f.generateCertificate(fin);
    PublicKey pk = certificate.getPublicKey();
    return String.format(Constants.PUBLIC_KEY, new String(Base64.encode(pk.getEncoded())));
}
 
開發者ID:xm-online,項目名稱:xm-ms-balance,代碼行數:19,代碼來源:MicroserviceSecurityConfiguration.java

示例15: getTrustManager

import java.security.cert.CertificateFactory; //導入依賴的package包/類
private static X509TrustManager getTrustManager() throws Exception {
    // generate certificate from cert string
    CertificateFactory cf = CertificateFactory.getInstance("X.509");

    // create a key store
    KeyStore ks = KeyStore.getInstance("JKS");
    ks.load(null, null);

    // import the trusted cert
    try (ByteArrayInputStream is =
            new ByteArrayInputStream(trustedCertStr.getBytes())) {
        Certificate trustedCert = cf.generateCertificate(is);
        ks.setCertificateEntry("RSA Export Signer", trustedCert);
    }

    // create the trust manager
    TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmAlgorithm);
    tmf.init(ks);

    return (X509TrustManager)tmf.getTrustManagers()[0];
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:22,代碼來源:ComodoHacker.java


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