当前位置: 首页>>代码示例>>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;未经允许,请勿转载。