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


Java X509Certificate.getSubjectDN方法代碼示例

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


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

示例1: loginByIDCard

import java.security.cert.X509Certificate; //導入方法依賴的package包/類
@Override
public Event loginByIDCard(RequestContext context) {
    SharedAttributeMap<Object> map = this.getSessionMap(context);
    try {
        this.statistics.collect(LocalDateTime.now(), context, AuthenticationType.IDCard, StatisticsOperation.START_AUTH);
        X509Certificate certificate = map.get(Constants.CERTIFICATE_SESSION_ATTRIBUTE, X509Certificate.class);
        Assert.notNull(certificate, "Unable to find certificate from session");
        this.checkCert(certificate);
        Principal subjectDN = certificate.getSubjectDN();
        Map<String, String> params = Splitter.on(", ").withKeyValueSeparator("=").split(subjectDN.getName());
        context.getFlowExecutionContext().getActiveSession().getScope()
            .put("credential", new TaraCredential(params.get("SERIALNUMBER"), params.get("GIVENNAME"), params.get("SURNAME")));
        this.statistics.collect(LocalDateTime.now(), context, AuthenticationType.IDCard, StatisticsOperation.SUCCESSFUL_AUTH);
        return new Event(this, "success");
    } catch (Exception e) {
        throw this.handleException(context, AuthenticationType.IDCard, e);
    } finally {
        map.remove(Constants.CERTIFICATE_SESSION_ATTRIBUTE);
    }
}
 
開發者ID:e-gov,項目名稱:TARA-Server,代碼行數:21,代碼來源:AuthenticationServiceImpl.java

示例2: getDnForCertificate

import java.security.cert.X509Certificate; //導入方法依賴的package包/類
private String getDnForCertificate(X509Certificate certificate) {
    if (certificate != null && certificate.getSubjectDN() != null) {
        return certificate.getSubjectDN().getName();
    }
    return "Unable to get DN";
}
 
開發者ID:alphagov,項目名稱:verify-hub,代碼行數:7,代碼來源:ConfigServiceKeyStore.java

示例3: main

import java.security.cert.X509Certificate; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {

        // Prepare a JKS keystore with many entries
        new File(JKSFILE).delete();
        for (int i=0; i<SIZE; i++) {
            System.err.print(".");
            String cmd = "-keystore " + JKSFILE
                    + " -storepass changeit -keypass changeit -keyalg rsa "
                    + "-genkeypair -alias p" + i + " -dname CN=" + i;
            sun.security.tools.keytool.Main.main(cmd.split(" "));
        }

        // Prepare EncryptedPrivateKeyInfo parameters, copied from various
        // places in PKCS12KeyStore.java
        AlgorithmParameters algParams =
                AlgorithmParameters.getInstance("PBEWithSHA1AndDESede");
        algParams.init(new PBEParameterSpec("12345678".getBytes(), 1024));
        AlgorithmId algid = new AlgorithmId(
                new ObjectIdentifier("1.2.840.113549.1.12.1.3"), algParams);

        PBEKeySpec keySpec = new PBEKeySpec(PASSWORD);
        SecretKeyFactory skFac = SecretKeyFactory.getInstance("PBE");
        SecretKey skey = skFac.generateSecret(keySpec);

        Cipher cipher = Cipher.getInstance("PBEWithSHA1AndDESede");
        cipher.init(Cipher.ENCRYPT_MODE, skey, algParams);

        // Pre-calculated keys and certs and aliases
        byte[][] keys = new byte[SIZE][];
        Certificate[][] certChains = new Certificate[SIZE][];
        String[] aliases = new String[SIZE];

        // Reads from JKS keystore and pre-calculate
        KeyStore ks = KeyStore.getInstance("jks");
        try (FileInputStream fis = new FileInputStream(JKSFILE)) {
            ks.load(fis, PASSWORD);
        }
        for (int i=0; i<SIZE; i++) {
            aliases[i] = "p" + i;
            byte[] enckey = cipher.doFinal(
                    ks.getKey(aliases[i], PASSWORD).getEncoded());
            keys[i] = new EncryptedPrivateKeyInfo(algid, enckey).getEncoded();
            certChains[i] = ks.getCertificateChain(aliases[i]);
        }

        // Write into PKCS12 keystore. Use this overloaded version of
        // setKeyEntry() to be as fast as possible, so that they would
        // have same localKeyId.
        KeyStore p12 = KeyStore.getInstance("pkcs12");
        p12.load(null, PASSWORD);
        for (int i=0; i<SIZE; i++) {
            p12.setKeyEntry(aliases[i], keys[i], certChains[i]);
        }
        try (FileOutputStream fos = new FileOutputStream(P12FILE)) {
            p12.store(fos, PASSWORD);
        }

        // Check private keys still match certs
        p12 = KeyStore.getInstance("pkcs12");
        try (FileInputStream fis = new FileInputStream(P12FILE)) {
            p12.load(fis, PASSWORD);
        }
        for (int i=0; i<SIZE; i++) {
            String a = "p" + i;
            X509Certificate x = (X509Certificate)p12.getCertificate(a);
            X500Name name = (X500Name)x.getSubjectDN();
            if (!name.getCommonName().equals(""+i)) {
                throw new Exception(a + "'s cert is " + name);
            }
        }
    }
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:72,代碼來源:PKCS12SameKeyId.java


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