public abstract class KeyRing extends Object implements Closeable
Closeable interface provides a
way to use this class (and its concrete sub-classes) in try-with-resources
blocks (Java7 and later).| Modifier and Type | Field and Description |
|---|---|
static String |
SIGNATURE_CRITICAL_EXTENSION_OID
The critical extension that signature certificates must have in order to
be recognised as valid for signing.
|
| Constructor and Description |
|---|
KeyRing() |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Attempts to log out of the KeyStore, and releases its reference.
|
protected abstract void |
closeImpl()
Logs out of the key store, if supported by the underlying technology.
|
List<String> |
enumerateAliases()
Returns a list of aliases for the given key store.
|
Certificate |
getCertificate(String alias)
Retrieves the certificate for the given alias.
|
List<Certificate> |
getCertificateChain(String signatureAlias)
Gets the certificate chain for the given alias.
|
Certificate[] |
getCertificateChainAsArray(String signatureAlias)
Gets the certificate chain for the given alias, as an array of Certificates.
|
KeyPair |
getKeyPair(String alias,
String password)
Gets a private and public key pair for the
given alias.
|
KeyStore |
getKeyStore()
Deprecated.
|
Key |
getPrivateKey(String alias)
Returns the private key (or a proxy) for the given alias.
|
Key |
getPrivateKey(String alias,
String password)
Returns the private key for the given alias, using the provided password
to unlock it; the key pair (private/public) password can differ from that
of the key store it is kept in.
|
Key |
getPublicKey(String alias)
Returns the public key for the given alias.
|
Key |
getPublicKey(String alias,
String password)
Returns the public key for the given alias, using the provided password
to unlock it; the key pair (private/public) password can differ from that
of the key store it is kept in.
|
List<String> |
getSignatureKeyAliases()
Retrieves a list of aliases corresponding to certificates that bear the
"signature" critical extension OID.
|
boolean |
isCertificateAlias(String alias)
Checks whether the alias has a corresponding certificate.
|
boolean |
isPrivateKeyAlias(String alias)
Checks whether the alias has a corresponding private key.
|
KeyRing |
open()
Acquires a reference to a KeyStore and returns its reference after having
logged in.
|
protected abstract KeyStore |
openImpl()
Loads and logs in to the key store.
|
public static final String SIGNATURE_CRITICAL_EXTENSION_OID
public KeyRing open() throws CryptoException
CryptoExceptionpublic void close()
close in interface Closeableclose in interface AutoCloseableCryptoExceptionprotected abstract KeyStore openImpl() throws CryptoException
CryptoException - if an I/O or a key store specific error occurs while loading the key
store.protected abstract void closeImpl()
throws CryptoException
CryptoException - if a communication error with the underlying device occurs.@Deprecated public KeyStore getKeyStore()
public List<String> enumerateAliases() throws CryptoException
CryptoException - if an error occurs while enumerating the aliases in the key store.public boolean isPrivateKeyAlias(String alias) throws CryptoException
alias - the name of the aliastrue if it corresponds to a private key, false
otherwise.CryptoException - if an error occurs while checking the given alias with the key store.public boolean isCertificateAlias(String alias) throws CryptoException
alias - the name of the alias.true if it corresponds to a certificate,
false otherwise.CryptoException - if an error occurs while checking the given alias with the key store.public Key getPrivateKey(String alias) throws CryptoException
alias - the name of the alias.CryptoException - if there was an error accessing the private key for the given alias.public Key getPrivateKey(String alias, String password) throws CryptoException
alias - the name of the alias.password - the private key password.CryptoException - if there was an error accessing the private key for the given alias.public Key getPublicKey(String alias) throws CryptoException
alias - the name of the alias.CryptoException - if there was an error accessing the public key for the given alias.public Key getPublicKey(String alias, String password) throws CryptoException
alias - the name of the alias.password - the public key password.CryptoException - if there was an error accessing the public key for the given alias.public Certificate getCertificate(String alias) throws CryptoException
alias - the name of the alias.CryptoException - if an error occurs extracting the certificate for the given alias from
the key store.public KeyPair getKeyPair(String alias, String password) throws CryptoException
alias - the name of the alias.password - the private an public key password.CryptoException - if an error occurs extracting either the private of the public key.public List<String> getSignatureKeyAliases() throws CryptoException
CryptoException - if it cannot enumerate aliases in the keystore.public List<Certificate> getCertificateChain(String signatureAlias) throws CryptoException
signatureAlias - the name of the alias.CryptoException - if it cannot reconstruct the certificate chain.public Certificate[] getCertificateChainAsArray(String signatureAlias) throws CryptoException
signatureAlias - the name of the alias.null if none found.CryptoException - if it cannot reconstruct the certificate chain.Copyright © 2012-2014 Andrea Funtò. See here for terms and conditions.