当前位置: 首页>>代码示例>>Java>>正文


Java KeyStore.aliases方法代码示例

本文整理汇总了Java中java.security.KeyStore.aliases方法的典型用法代码示例。如果您正苦于以下问题:Java KeyStore.aliases方法的具体用法?Java KeyStore.aliases怎么用?Java KeyStore.aliases使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.security.KeyStore的用法示例。


在下文中一共展示了KeyStore.aliases方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getCertIdIdByStore

import java.security.KeyStore; //导入方法依赖的package包/类
/**
 * 通过keystore获取私钥证书的certId值
 * @param keyStore
 * @return
 */
private static String getCertIdIdByStore(KeyStore keyStore) {
	Enumeration<String> aliasenum = null;
	try {
		aliasenum = keyStore.aliases();
		String keyAlias = null;
		if (aliasenum.hasMoreElements()) {
			keyAlias = aliasenum.nextElement();
		}
		X509Certificate cert = (X509Certificate) keyStore
				.getCertificate(keyAlias);
		return cert.getSerialNumber().toString();
	} catch (KeyStoreException e) {
		log.error("getCertIdIdByStore Error", e);
		return null;
	}
}
 
开发者ID:howe,项目名称:nutz-pay,代码行数:22,代码来源:CertUtil.java

示例2: loadPfx

import java.security.KeyStore; //导入方法依赖的package包/类
public void loadPfx(InputStream is, String password)
		throws NoSuchAlgorithmException,
			CertificateException,
			IOException,
			KeyStoreException,
			UnrecoverableEntryException {

	char[] pwd = password.toCharArray();
	KeyStore keyStore = KeyStore.getInstance("pkcs12");
	keyStore.load(is, pwd);
	PasswordProtection passwordProtection = new KeyStore.PasswordProtection(pwd);

	for (Enumeration<String> aliases = keyStore.aliases(); aliases.hasMoreElements();) {
		String alias = aliases.nextElement();
		KeyStore.PrivateKeyEntry entry = (KeyStore.PrivateKeyEntry) keyStore.getEntry(alias, passwordProtection);
		Certificate cert = entry.getCertificate();
		if (cert.getType().equals("X.509")) {
			this.certificate = (X509Certificate) cert;
			this.privateKey = entry.getPrivateKey();
			return;
		}
	}
	throw new RuntimeException("Certificate of type X.509 was not found.");

}
 
开发者ID:EixoX,项目名称:jetfuel,代码行数:26,代码来源:X509CertificateWithKey.java

示例3: PKIXParameters

import java.security.KeyStore; //导入方法依赖的package包/类
/**
 * Creates an instance of {@code PKIXParameters} that
 * populates the set of most-trusted CAs from the trusted
 * certificate entries contained in the specified {@code KeyStore}.
 * Only keystore entries that contain trusted {@code X509Certificates}
 * are considered; all other certificate types are ignored.
 *
 * @param keystore a {@code KeyStore} from which the set of
 * most-trusted CAs will be populated
 * @throws KeyStoreException if the keystore has not been initialized
 * @throws InvalidAlgorithmParameterException if the keystore does
 * not contain at least one trusted certificate entry
 * @throws NullPointerException if the keystore is {@code null}
 */
public PKIXParameters(KeyStore keystore)
    throws KeyStoreException, InvalidAlgorithmParameterException
{
    if (keystore == null)
        throw new NullPointerException("the keystore parameter must be " +
            "non-null");
    Set<TrustAnchor> hashSet = new HashSet<TrustAnchor>();
    Enumeration<String> aliases = keystore.aliases();
    while (aliases.hasMoreElements()) {
        String alias = aliases.nextElement();
        if (keystore.isCertificateEntry(alias)) {
            Certificate cert = keystore.getCertificate(alias);
            if (cert instanceof X509Certificate)
                hashSet.add(new TrustAnchor((X509Certificate)cert, null));
        }
    }
    setTrustAnchors(hashSet);
    this.unmodInitialPolicies = Collections.<String>emptySet();
    this.certPathCheckers = new ArrayList<PKIXCertPathChecker>();
    this.certStores = new ArrayList<CertStore>();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:36,代码来源:PKIXParameters.java

示例4: keystorecerts2Hashtable

import java.security.KeyStore; //导入方法依赖的package包/类
/**
 * Stores the (leaf) certificates of a keystore in a hashtable.
 * All certs belonging to the same CA are stored in a vector that
 * in turn is stored in the hashtable, keyed by the CA's subject DN
 */
private void keystorecerts2Hashtable(KeyStore ks,
            Hashtable<Principal, Vector<Certificate>> hash)
    throws Exception {

    for (Enumeration<String> aliases = ks.aliases();
                                    aliases.hasMoreElements(); ) {
        String alias = aliases.nextElement();
        Certificate cert = ks.getCertificate(alias);
        if (cert != null) {
            Principal subjectDN = ((X509Certificate)cert).getSubjectDN();
            Vector<Certificate> vec = hash.get(subjectDN);
            if (vec == null) {
                vec = new Vector<Certificate>();
                vec.addElement(cert);
            } else {
                if (!vec.contains(cert)) {
                    vec.addElement(cert);
                }
            }
            hash.put(subjectDN, vec);
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:29,代码来源:Main.java

示例5: execute0

import java.security.KeyStore; //导入方法依赖的package包/类
@Override
protected Object execute0() throws Exception {
    KeyStore ks = getKeyStore();

    String keyname = null;
    Enumeration<String> aliases = ks.aliases();
    while (aliases.hasMoreElements()) {
        String alias = aliases.nextElement();
        if (ks.isKeyEntry(alias)) {
            keyname = alias;
            break;
        }
    }

    if (keyname == null) {
        throw new CmdFailure("could not find private key");
    }

    X509Certificate cert = (X509Certificate) ks.getCertificate(keyname);
    saveVerbose("saved certificate to file", new File(outFile), cert.getEncoded());

    return null;
}
 
开发者ID:xipki,项目名称:xitk,代码行数:24,代码来源:P12CertExportCmd.java

示例6: getTrustedSigner

import java.security.KeyStore; //导入方法依赖的package包/类
/**
 * Locates a signer for a given certificate from a given keystore and
 * returns the signer's certificate.
 * @param cert the certificate whose signer is searched, not null
 * @param ks the keystore to search with, not null
 * @return <code>cert</code> itself if it's already inside <code>ks</code>,
 * or a certificate inside <code>ks</code> who signs <code>cert</code>,
 * or null otherwise.
 */
private static Certificate getTrustedSigner(Certificate cert, KeyStore ks)
        throws Exception {
    if (ks.getCertificateAlias(cert) != null) {
        return cert;
    }
    for (Enumeration<String> aliases = ks.aliases();
            aliases.hasMoreElements(); ) {
        String name = aliases.nextElement();
        Certificate trustedCert = ks.getCertificate(name);
        if (trustedCert != null) {
            try {
                cert.verify(trustedCert.getPublicKey());
                return trustedCert;
            } catch (Exception e) {
                // Not verified, skip to the next one
            }
        }
    }
    return null;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:30,代码来源:Main.java

示例7: verifySignature

import java.security.KeyStore; //导入方法依赖的package包/类
/**
 * Iterates over the certificates stored in the truststore to verify the signature of the provided certificate
 * 
 * @param trustStoreFilename The relative path and file name of the truststore
 * @param certificate The certificate whose signature needs to be signed
 * @return True, if the provided certificate has been signed by one of the certificates in the 
 * 		   truststore, false otherwise
 */
public static boolean verifySignature(X509Certificate certificate, String trustStoreFilename) {
	KeyStore trustStore = SecurityUtils.getTrustStore(trustStoreFilename, GlobalValues.PASSPHRASE_FOR_CERTIFICATES_AND_KEYS.toString());
	X500Principal expectedIssuer = certificate.getIssuerX500Principal();
	
	try {
		Enumeration<String> aliases = trustStore.aliases();
		while (aliases.hasMoreElements()) {
			X509Certificate rootCA = (X509Certificate) trustStore.getCertificate(aliases.nextElement());
			if (rootCA.getSubjectX500Principal().getName().equals(expectedIssuer.getName()) &&
				verifySignature(certificate, rootCA)) return true;
		}
	} catch (KeyStoreException | NullPointerException e) {
		getLogger().error(e.getClass().getSimpleName() + " occurred while trying to verify trust " +
						  "status of certificate with distinguished name '" + 
						  certificate.getSubjectX500Principal().getName() + "' with truststore at " +
						  "location '" + trustStoreFilename + "'", e);
	}
	
	return false;
}
 
开发者ID:V2GClarity,项目名称:RISE-V2G,代码行数:29,代码来源:SecurityUtils.java

示例8: initializeTrustedCACertificatesFromKeyStore

import java.security.KeyStore; //导入方法依赖的package包/类
private void initializeTrustedCACertificatesFromKeyStore() {
  try {
    InputStream is = AuthenticationResponseValidator.class.getResourceAsStream("/trusted_certificates.jks");
    KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
    keystore.load(is, "changeit".toCharArray());
    Enumeration<String> aliases = keystore.aliases();
    while (aliases.hasMoreElements()) {
      String alias = aliases.nextElement();
      X509Certificate certificate = (X509Certificate) keystore.getCertificate(alias);
      addTrustedCACertificate(certificate);
    }
  } catch (IOException | CertificateException | KeyStoreException | NoSuchAlgorithmException e) {
    logger.error("Error initializing trusted CA certificates", e);
    throw new TechnicalErrorException("Error initializing trusted CA certificates", e);
  }
}
 
开发者ID:SK-EID,项目名称:smart-id-java-client,代码行数:17,代码来源:AuthenticationResponseValidator.java

示例9: main

import java.security.KeyStore; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    // Try to register a JCE provider from property sun.security.mscapi.testprovider in the first slot
    // otherwise register a dummy provider which would provoke the issue of bug 8139436
    boolean providerPrepended = false;
    String testprovider = System.getProperty("sun.security.mscapi.testprovider");
    if (testprovider != null && !testprovider.isEmpty()) {
        try {
            System.out.println("Trying to prepend external JCE provider " + testprovider);
            Class<?> providerclass = Class.forName(testprovider);
            Object provider = providerclass.newInstance();
            Security.insertProviderAt((Provider)provider, 1);
        } catch (Exception e) {
            System.out.println("Could not load JCE provider " + testprovider +". Exception is:");
            e.printStackTrace(System.out);
        }
        providerPrepended = true;
        System.out.println("Sucessfully prepended JCE provider " + testprovider);
    }
    if (!providerPrepended) {
        System.out.println("Trying to prepend dummy JCE provider");
        Security.insertProviderAt(new TestProvider(), 1);
        System.out.println("Sucessfully prepended dummy JCE provider");
    }

    // load Windows-ROOT KeyStore
    KeyStore keyStore = KeyStore.getInstance("Windows-ROOT", "SunMSCAPI");
    keyStore.load(null, null);

    // iterate KeyStore
    Enumeration<String> aliases = keyStore.aliases();
    while (aliases.hasMoreElements()) {
        String alias = aliases.nextElement();
        System.out.print("Reading certificate for alias: " + alias + "...");
        keyStore.getCertificate(alias);
        System.out.println(" done.");
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:38,代码来源:IterateWindowsRootStore.java

示例10: keystorecerts2Hashtable

import java.security.KeyStore; //导入方法依赖的package包/类
/**
 * Stores the (leaf) certificates of a keystore in a hashtable.
 * All certs belonging to the same CA are stored in a vector that
 * in turn is stored in the hashtable, keyed by the CA's subject DN.
 * Each cert comes with a string label that shows its origin and alias.
 */
private void keystorecerts2Hashtable(KeyStore ks,
            Hashtable<Principal, Vector<Pair<String,X509Certificate>>> hash)
    throws Exception {

    for (Enumeration<String> aliases = ks.aliases();
                                    aliases.hasMoreElements(); ) {
        String alias = aliases.nextElement();
        Certificate cert = ks.getCertificate(alias);
        if (cert != null) {
            Principal subjectDN = ((X509Certificate)cert).getSubjectDN();
            Pair<String,X509Certificate> pair = new Pair<>(
                    String.format(
                            rb.getString(ks == caks ?
                                    "alias.in.cacerts" :
                                    "alias.in.keystore"),
                            alias),
                    (X509Certificate)cert);
            Vector<Pair<String,X509Certificate>> vec = hash.get(subjectDN);
            if (vec == null) {
                vec = new Vector<>();
                vec.addElement(pair);
            } else {
                if (!vec.contains(pair)) {
                    vec.addElement(pair);
                }
            }
            hash.put(subjectDN, vec);
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:37,代码来源:Main.java

示例11: KeyStoreResolver

import java.security.KeyStore; //导入方法依赖的package包/类
/**
 * Constructor KeyStoreResolver
 *
 * @param keyStore is the keystore which contains the Certificates
 * @throws StorageResolverException
 */
public KeyStoreResolver(KeyStore keyStore) throws StorageResolverException {
    this.keyStore = keyStore;
    // Do a quick check on the keystore
    try {
        keyStore.aliases();
    } catch (KeyStoreException ex) {
        throw new StorageResolverException("generic.EmptyMessage", ex);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:16,代码来源:KeyStoreResolver.java

示例12: SoftTokenMacContentSignerBuilder

import java.security.KeyStore; //导入方法依赖的package包/类
public SoftTokenMacContentSignerBuilder(String keystoreType, InputStream keystoreStream,
        char[] keystorePassword, String keyname, char[] keyPassword)
        throws XiSecurityException {
    if (!"JCEKS".equalsIgnoreCase(keystoreType)) {
        throw new IllegalArgumentException("unsupported keystore type: " + keystoreType);
    }
    ParamUtil.requireNonNull("keystoreStream", keystoreStream);
    ParamUtil.requireNonNull("keystorePassword", keystorePassword);
    ParamUtil.requireNonNull("keyPassword", keyPassword);

    try {
        KeyStore ks = KeyUtil.getKeyStore(keystoreType);
        ks.load(keystoreStream, keystorePassword);

        String tmpKeyname = keyname;
        if (tmpKeyname == null) {
            Enumeration<String> aliases = ks.aliases();
            while (aliases.hasMoreElements()) {
                String alias = aliases.nextElement();
                if (ks.isKeyEntry(alias)) {
                    tmpKeyname = alias;
                    break;
                }
            }
        } else {
            if (!ks.isKeyEntry(tmpKeyname)) {
                throw new XiSecurityException("unknown key named " + tmpKeyname);
            }
        }

        this.key = (SecretKey) ks.getKey(tmpKeyname, keyPassword);
    } catch (KeyStoreException | NoSuchProviderException | NoSuchAlgorithmException
            | CertificateException | IOException | UnrecoverableKeyException
            | ClassCastException ex) {
        throw new XiSecurityException(ex.getMessage(), ex);
    }
}
 
开发者ID:xipki,项目名称:xitk,代码行数:38,代码来源:SoftTokenMacContentSignerBuilder.java

示例13: execute0

import java.security.KeyStore; //导入方法依赖的package包/类
@Override
protected Object execute0() throws Exception {
    KeyStore ks = getKeyStore();

    char[] pwd = getPassword();
    X509Certificate newCert = X509Util.parseCert(certFile);

    assertMatch(newCert, new String(pwd));

    String keyname = null;
    Enumeration<String> aliases = ks.aliases();
    while (aliases.hasMoreElements()) {
        String alias = aliases.nextElement();
        if (ks.isKeyEntry(alias)) {
            keyname = alias;
            break;
        }
    }

    if (keyname == null) {
        throw new XiSecurityException("could not find private key");
    }

    Key key = ks.getKey(keyname, pwd);
    Set<X509Certificate> caCerts = new HashSet<>();
    if (isNotEmpty(caCertFiles)) {
        for (String caCertFile : caCertFiles) {
            caCerts.add(X509Util.parseCert(caCertFile));
        }
    }
    X509Certificate[] certChain = X509Util.buildCertPath(newCert, caCerts);
    ks.setKeyEntry(keyname, key, pwd, certChain);

    try (FileOutputStream out = new FileOutputStream(p12File)) {
        ks.store(out, pwd);
        println("updated certificate");
        return null;
    }
}
 
开发者ID:xipki,项目名称:xitk,代码行数:40,代码来源:P12CertUpdateCmd.java

示例14: run

import java.security.KeyStore; //导入方法依赖的package包/类
@Override
public Void run() {
    File f = new File(System.getProperty("java.home"),
            "lib/security/cacerts");
    KeyStore cacerts;
    try {
        cacerts = KeyStore.getInstance("JKS");
        try (FileInputStream fis = new FileInputStream(f)) {
            cacerts.load(fis, null);
            certs = new HashSet<>();
            Enumeration<String> list = cacerts.aliases();
            String alias;
            while (list.hasMoreElements()) {
                alias = list.nextElement();
                // Check if this cert is labeled a trust anchor.
                if (alias.contains(" [jdk")) {
                    X509Certificate cert = (X509Certificate) cacerts
                            .getCertificate(alias);
                    certs.add(X509CertImpl.getFingerprint(HASH, cert));
                }
            }
        }
    } catch (Exception e) {
        if (debug != null) {
            debug.println("Error parsing cacerts");
        }
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:31,代码来源:AnchorCertificates.java

示例15: main

import java.security.KeyStore; //导入方法依赖的package包/类
public static void main(String... args)
    throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException {
  KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
  ks.aliases();
}
 
开发者ID:themaplelab,项目名称:ideal,代码行数:6,代码来源:KeyStoreTarget2.java


注:本文中的java.security.KeyStore.aliases方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。