Bruce
Search…
Key Stores
For managing Java key stores, I suggest using KeyStore Explorer.

Default

1
KeyStore keystore();
Copied!
Returns the default key store using configuration from the following system properties:
  • javax.net.ssl.keyStore
  • javax.net.ssl.keyStorePassword
The key store location supports the following protocols:
  • classpath:
  • http:
  • https:
  • file:
    If no protocol is specified, file is assumed. The default key store type is PKCS12.

Usage Example

1
KeyStore keystore = keystore();
Copied!

Default with Type

1
KeyStore keystore(String type);
Copied!
Same as above but the key store type can be specified. For instance, valid types include: JKS, PKCS12.

Usage Example

1
KeyStore keystore = keystore("JKS");
Copied!

From Location

1
KeyStore keystore(
2
String location,
3
char[] password
4
);
Copied!
Loads a key store from the given location.
The location parameter supports the protocols described in the default key store api method.
The key store is opened with the given password.
The key store type is assumed to be the default: PKCS12.

Usage Example

1
// load key store from classpath
2
KeyStore keystore = keystore(
3
"classpath:keystore.p12",
4
"password".toCharArray()
5
);
Copied!
1
// load key store from file
2
KeyStore keystore = keystore(
3
"file:/etc/myapp/keystore.p12",
4
"password".toCharArray()
5
);
Copied!
1
// load key store from https
2
KeyStore keystore = keystore(
3
"https://acme.com/sec/keystore.p12",
4
"password".toCharArray()
5
);
Copied!

From Location with Type

1
KeyStore keystore(
2
String location,
3
char[] password,
4
String type
5
);
Copied!
Same as in from location but allows you to specify a key store type. For instance, valid types include: JKS, PKCS12.

Usage Examples

1
// use JKS as the key store type
2
KeyStore keystore = keystore(
3
"classpath:keystore.jks",
4
"password".toCharArray(),
5
"JKS"
6
);
Copied!
1
// use PKCS12 as the key store type
2
KeyStore keystore = keystore(
3
"classpath:keystore.p12",
4
"password".toCharArray(),
5
"PKCS12"
6
);
Copied!
Last modified 6mo ago