本文整理了Java中java.security.KeyStore.size()
方法的一些代码示例,展示了KeyStore.size()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。KeyStore.size()
方法的具体详情如下:
包路径:java.security.KeyStore
类名称:KeyStore
方法名:size
[英]Returns the number of entries stored in this KeyStore.
[中]返回存储在此密钥库中的条目数。
代码示例来源:origin: wildfly/wildfly
@Override
public int engineSize() {
try {
return getKeyStore().size();
} catch (KeyStoreException e) {
throw new IllegalStateException(e);
}
}
代码示例来源:origin: elastic/elasticsearch-hadoop
public List<String> listEntries() throws EsHadoopSecurityException {
try {
List<String> entries = new ArrayList<String>(keyStore.size());
Enumeration<String> aliases = keyStore.aliases();
while (aliases.hasMoreElements()) {
String alias = aliases.nextElement();
entries.add(alias);
}
return entries;
} catch (KeyStoreException e) {
throw new EsHadoopSecurityException("Could not read aliases from keystore", e);
}
}
代码示例来源:origin: igniterealtime/Openfire
try {
int numberOfEntry = trustStore.size();
代码示例来源:origin: AsyncHttpClient/async-http-client
private static TrustManager[] createTrustManagers() throws GeneralSecurityException, IOException {
KeyStore ks = KeyStore.getInstance("JKS");
try (InputStream keyStoreStream = TestUtils.class.getClassLoader().getResourceAsStream("ssltest-keystore.jks")) {
char[] keyStorePassword = "changeit".toCharArray();
ks.load(keyStoreStream, keyStorePassword);
}
assert (ks.size() > 0);
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(ks);
return tmf.getTrustManagers();
}
代码示例来源:origin: stackoverflow.com
HttpClient httpclient = new DefaultHttpClient();
// truststore
KeyStore ts = KeyStore.getInstance("JKS", "SUN");
ts.load(PostService.class.getResourceAsStream("/truststore.jks"), "amber%".toCharArray());
// if you remove me, you've got 'javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated' on missing truststore
if(0 == ts.size()) throw new IOException("Error loading truststore");
// tmf
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(ts);
// keystore
KeyStore ks = KeyStore.getInstance("PKCS12", "SunJSSE");
ks.load(PostService.class.getResourceAsStream("/" + certName), certPwd.toCharArray());
// if you remove me, you've got 'javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated' on missing keystore
if(0 == ks.size()) throw new IOException("Error loading keystore");
// kmf
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(ks, certPwd.toCharArray());
// SSL
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
// socket
SSLSocketFactory socketFactory = new SSLSocketFactory(ctx, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
Scheme sch = new Scheme("https", 8443, socketFactory);
httpclient.getConnectionManager().getSchemeRegistry().register(sch);
// request
HttpMethod get = new GetMethod("https://localhost:8443/foo");
client.executeMethod(get);
IOUtils.copy(get.getResponseBodyAsStream(), System.out);
代码示例来源:origin: igniterealtime/Openfire
try {
int numberOfEntry = trustStore.size();
代码示例来源:origin: AsyncHttpClient/async-http-client
private static KeyManager[] createKeyManagers() throws GeneralSecurityException, IOException {
KeyStore ks = KeyStore.getInstance("JKS");
try (InputStream keyStoreStream = TestUtils.class.getClassLoader().getResourceAsStream("ssltest-cacerts.jks")) {
char[] keyStorePassword = "changeit".toCharArray();
ks.load(keyStoreStream, keyStorePassword);
}
assert (ks.size() > 0);
// Set up key manager factory to use our key store
char[] certificatePassword = "changeit".toCharArray();
KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
kmf.init(ks, certificatePassword);
// Initialize the SSLContext to work with our key managers.
return kmf.getKeyManagers();
}
代码示例来源:origin: stackoverflow.com
trustStore.load(clientTruststoreIs, "MyPassword".toCharArray());
System.out.println("Loaded server certificates: " + trustStore.size());
keyStore.load(keyStoreStream, "MyPassword".toCharArray());
System.out.println("Loaded client certificates: " + keyStore.size());
代码示例来源:origin: robovm/robovm
if (keyStore.size() == 0) {
throw new InvalidAlgorithmParameterException("keyStore.size() == 0");
代码示例来源:origin: stackoverflow.com
int nBefore = keyStore.size();
int nAfter = keyStore.size();
Log.v(TAG, "Before = " + nBefore + " After = " + nAfter);
代码示例来源:origin: igniterealtime/Openfire
boolean hasCertificates = false;
try {
hasCertificates = XMPPServer.getInstance().getCertificateStoreManager().getIdentityStore( ConnectionType.SOCKET_S2S ).getStore().size() > 0;
代码示例来源:origin: apache/zookeeper
@Test
public void testLoadTrustStore() throws Exception {
String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.PEM)
.getAbsolutePath();
KeyStore ts = new PEMFileLoader.Builder()
.setTrustStorePath(path)
.setTrustStorePassword(x509TestContext.getTrustStorePassword())
.build()
.loadTrustStore();
Assert.assertEquals(1, ts.size());
}
代码示例来源:origin: apache/zookeeper
@Test
public void testLoadKeyStore() throws Exception {
String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.JKS)
.getAbsolutePath();
KeyStore ks = new JKSFileLoader.Builder()
.setKeyStorePath(path)
.setKeyStorePassword(x509TestContext.getKeyStorePassword())
.build()
.loadKeyStore();
Assert.assertEquals(1, ks.size());
}
代码示例来源:origin: apache/zookeeper
@Test
public void testLoadTrustStore() throws Exception {
String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.JKS)
.getAbsolutePath();
KeyStore ts = new JKSFileLoader.Builder()
.setTrustStorePath(path)
.setTrustStorePassword(x509TestContext.getTrustStorePassword())
.build()
.loadTrustStore();
Assert.assertEquals(1, ts.size());
}
代码示例来源:origin: apache/zookeeper
@Test
public void testLoadKeyStore() throws Exception {
String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.PEM)
.getAbsolutePath();
KeyStore ks = new PEMFileLoader.Builder()
.setKeyStorePath(path)
.setKeyStorePassword(x509TestContext.getKeyStorePassword())
.build()
.loadKeyStore();
Assert.assertEquals(1, ks.size());
}
代码示例来源:origin: apache/zookeeper
@Test
public void testLoadTrustStoreWithWrongFileType() throws Exception {
// Trying to load a JKS file with PEM loader should fail
String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.JKS)
.getAbsolutePath();
KeyStore ts = new PEMFileLoader.Builder()
.setTrustStorePath(path)
.setTrustStorePassword(x509TestContext.getTrustStorePassword())
.build()
.loadTrustStore();
Assert.assertEquals(0, ts.size());
}
}
代码示例来源:origin: wildfly/wildfly
} else {
if (keyStoreSupplier.get().size() > 1) {
throw xmlLog.missingAlias(location);
} else if (keyStoreSupplier.get().aliases().hasMoreElements()) {
代码示例来源:origin: wildfly/wildfly
keyStore = FilteringKeyStore.filteringKeyStore(keyStore, AliasFilter.fromString(finalAlias));
if (xmlLog.isTraceEnabled()) xmlLog.tracef("Filtered aliases %s", aliasesToString(keyStore.aliases()));
if (keyStore.size() < 1) throw xmlLog.keyStoreEntryMissing(location, finalAlias);
代码示例来源:origin: fabric8io/kubernetes-client
@Test
public void testLoadKeyStoreFromFileUsingSystemProperties()
throws InvalidKeySpecException, CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, URISyntaxException {
System.setProperty(CertUtils.KEY_STORE_SYSTEM_PROPERTY, FABRIC8_STORE_PATH);
System.setProperty(CertUtils.KEY_STORE_PASSWORD_SYSTEM_PROPERTY, String.valueOf(FABRIC8_STORE_PASSPHRASE));
String privateKeyPath = Utils.filePath(getClass().getResource("/ssl/fabric8"));
String multipleCertsPath = Utils.filePath(getClass().getResource("/ssl/multiple-certs.pem"));
KeyStore trustStore =
CertUtils.createKeyStore(null, multipleCertsPath, null, privateKeyPath, "RSA", "changeit", null, null);
assertEquals(2, trustStore.size());
verifyFabric8InStore(trustStore);
}
代码示例来源:origin: fabric8io/kubernetes-client
@Test
public void testLoadTrustStoreFromFileUsingSystemProperties()
throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException {
System.setProperty(CertUtils.TRUST_STORE_SYSTEM_PROPERTY, FABRIC8_STORE_PATH);
System.setProperty(CertUtils.TRUST_STORE_PASSWORD_SYSTEM_PROPERTY, String.valueOf(FABRIC8_STORE_PASSPHRASE));
KeyStore trustStore =
CertUtils.createTrustStore(getMultipleCertsInputSteam(), null, null);
assertEquals(3, trustStore.size());
verifyFabric8InStore(trustStore);
}
内容来源于网络,如有侵权,请联系作者删除!