Bruce
  • Welcome
  • Essentials
    • Features
    • Getting Started
    • General Concepts
    • Roadmap
  • API
    • Cheat Sheet
    • Key Stores
    • Certificates
    • Keys
    • Digests
    • Signatures
    • Verification
    • Symmetric Ciphers
    • Asymmetric Ciphers
    • Message Authentication Codes
Powered by GitBook
On this page
  • Default
  • Usage Example
  • Default with Type
  • Usage Example
  • From Location
  • Usage Example
  • From Location with Type
  • Usage Examples

Was this helpful?

Export as PDF
  1. API

Key Stores

PreviousCheat SheetNextCertificates

Last updated 3 years ago

Was this helpful?

For managing Java key stores, I suggest using .

Default

KeyStore keystore();

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

KeyStore keystore = keystore();

Default with Type

KeyStore keystore(String type);

Usage Example

KeyStore keystore = keystore("JKS");

From Location

KeyStore keystore(
    String location, 
    char[] password
);

Loads a key store from the given location.

The key store is opened with the given password.

The key store type is assumed to be the default: PKCS12.

Usage Example

// load key store from classpath
KeyStore keystore = keystore(
    "classpath:keystore.p12", 
    "password".toCharArray()
);
// load key store from file
KeyStore keystore = keystore(
    "file:/etc/myapp/keystore.p12", 
    "password".toCharArray()
);
// load key store from https
KeyStore keystore = keystore(
    "https://acme.com/sec/keystore.p12", 
    "password".toCharArray()
);

From Location with Type

KeyStore keystore(
    String location, 
    char[] password, 
    String type
);

Usage Examples

// use JKS as the key store type
KeyStore keystore = keystore(
    "classpath:keystore.jks", 
    "password".toCharArray(), 
    "JKS"
);
// use PKCS12 as the key store type
KeyStore keystore = keystore(
    "classpath:keystore.p12", 
    "password".toCharArray(), 
    "PKCS12"
);

Same as but the key store type can be specified. For instance, valid types include: JKS, PKCS12.

The location parameter supports the protocols described in the api method.

Same as in but allows you to specify a key store type. For instance, valid types include: JKS, PKCS12.

KeyStore Explorer
above
default key store
from location