Package java.security
Class KeyStoreSpi
java.lang.Object
java.security.KeyStoreSpi
- Direct Known Subclasses:
BcKeyStoreSpi,PKCS12KeyStoreSpi,TrustedCertificateKeyStoreSpi
public abstract class KeyStoreSpi extends Object
KeyStoreSpi is the Service Provider Interface (SPI) definition for
KeyStore.- See Also:
KeyStore
-
Constructor Summary
Constructors Constructor Description KeyStoreSpi() -
Method Summary
Modifier and Type Method Description abstract Enumeration<String>engineAliases()Returns anEnumerationover all alias names stored in thisKeyStoreSpi.abstract booleanengineContainsAlias(String alias)Indicates whether the given alias is present in thisKeyStoreSpi.abstract voidengineDeleteEntry(String alias)Deletes the entry identified with the given alias from thisKeyStoreSpi.booleanengineEntryInstanceOf(String alias, Class<? extends KeyStore.Entry> entryClass)Indicates whether the entry for the given alias is assignable to the providedClass.abstract CertificateengineGetCertificate(String alias)Returns the trusted certificate for the entry with the given alias.abstract StringengineGetCertificateAlias(Certificate cert)Returns the alias associated with the first entry whose certificate matches the specified certificate.abstract Certificate[]engineGetCertificateChain(String alias)Returns the certificate chain for the entry with the given alias.abstract DateengineGetCreationDate(String alias)Returns the creation date of the entry with the given alias.KeyStore.EntryengineGetEntry(String alias, KeyStore.ProtectionParameter protParam)Returns theEntrywith the given alias, using the specifiedProtectionParameter.abstract KeyengineGetKey(String alias, char[] password)Returns the key with the given alias, using the password to recover the key from the store.abstract booleanengineIsCertificateEntry(String alias)Indicates whether the specified alias is associated with aKeyStore.TrustedCertificateEntry.abstract booleanengineIsKeyEntry(String alias)Indicates whether the specified alias is associated with either aKeyStore.PrivateKeyEntryor aKeyStore.SecretKeyEntry.abstract voidengineLoad(InputStream stream, char[] password)Loads thisKeyStoreSpifrom the givenInputStream.voidengineLoad(KeyStore.LoadStoreParameter param)Loads thisKeyStoreSpiusing the specifiedLoadStoreParameter.abstract voidengineSetCertificateEntry(String alias, Certificate cert)Associates the given alias with a certificate.voidengineSetEntry(String alias, KeyStore.Entry entry, KeyStore.ProtectionParameter protParam)Stores the givenEntryin thisKeyStoreSpiand associates the entry with the givenalias.abstract voidengineSetKeyEntry(String alias, byte[] key, Certificate[] chain)Associates the given alias with a key and a certificate chain.abstract voidengineSetKeyEntry(String alias, Key key, char[] password, Certificate[] chain)Associates the given alias with the key, password and certificate chain.abstract intengineSize()Returns the number of entries stored in thisKeyStoreSpi.abstract voidengineStore(OutputStream stream, char[] password)Writes thisKeyStoreSpito the specifiedOutputStream.voidengineStore(KeyStore.LoadStoreParameter param)Stores thisKeyStoreSpiusing the specifiedLoadStoreParameter.
-
Constructor Details
-
KeyStoreSpi
public KeyStoreSpi()
-
-
Method Details
-
engineGetKey
public abstract Key engineGetKey(String alias, char[] password) throws NoSuchAlgorithmException, UnrecoverableKeyExceptionReturns the key with the given alias, using the password to recover the key from the store.- Parameters:
alias- the alias for the entry.password- the password used to recover the key.- Returns:
- the key with the specified alias, or
nullif the specified alias is not bound to an entry. - Throws:
NoSuchAlgorithmException- if the algorithm for recovering the key is not available.UnrecoverableKeyException- if the key can not be recovered.
-
engineGetCertificateChain
Returns the certificate chain for the entry with the given alias.- Parameters:
alias- the alias for the entry- Returns:
- the certificate chain for the entry with the given alias, or
nullif the specified alias is not bound to an entry.
-
engineGetCertificate
Returns the trusted certificate for the entry with the given alias.- Parameters:
alias- the alias for the entry.- Returns:
- the trusted certificate for the entry with the given alias, or
nullif the specified alias is not bound to an entry.
-
engineGetCreationDate
Returns the creation date of the entry with the given alias.- Parameters:
alias- the alias for the entry.- Returns:
- the creation date, or
nullif the specified alias is not bound to an entry.
-
engineSetKeyEntry
public abstract void engineSetKeyEntry(String alias, Key key, char[] password, Certificate[] chain) throws KeyStoreExceptionAssociates the given alias with the key, password and certificate chain.If the specified alias already exists, it will be reassigned.
- Parameters:
alias- the alias for the key.key- the key.password- the password.chain- the certificate chain.- Throws:
KeyStoreException- if the specified key can not be protected, or if this operation fails for another reason.IllegalArgumentException- ifkeyis aPrivateKeyandchaindoes not contain any certificates.
-
engineSetKeyEntry
public abstract void engineSetKeyEntry(String alias, byte[] key, Certificate[] chain) throws KeyStoreExceptionAssociates the given alias with a key and a certificate chain.If the specified alias already exists, it will be reassigned.
- Parameters:
alias- the alias for the key.key- the key in an encoded format.chain- the certificate chain.- Throws:
KeyStoreException- if this operation fails.IllegalArgumentException- ifkeyis aPrivateKeyandchaindoes.
-
engineSetCertificateEntry
public abstract void engineSetCertificateEntry(String alias, Certificate cert) throws KeyStoreExceptionAssociates the given alias with a certificate.If the specified alias already exists, it will be reassigned.
- Parameters:
alias- the alias for the certificate.cert- the certificate.- Throws:
KeyStoreException- if an existing alias is not associated to an entry containing a trusted certificate, or this method fails for any other reason.
-
engineDeleteEntry
Deletes the entry identified with the given alias from thisKeyStoreSpi.- Parameters:
alias- the alias for the entry.- Throws:
KeyStoreException- if the entry can not be deleted.
-
engineAliases
Returns anEnumerationover all alias names stored in thisKeyStoreSpi.- Returns:
- an
Enumerationover all alias names stored in thisKeyStoreSpi.
-
engineContainsAlias
Indicates whether the given alias is present in thisKeyStoreSpi.- Parameters:
alias- the alias of an entry.- Returns:
trueif the alias exists,falseotherwise.
-
engineSize
public abstract int engineSize()Returns the number of entries stored in thisKeyStoreSpi.- Returns:
- the number of entries stored in this
KeyStoreSpi.
-
engineIsKeyEntry
Indicates whether the specified alias is associated with either aKeyStore.PrivateKeyEntryor aKeyStore.SecretKeyEntry.- Parameters:
alias- the alias of an entry.- Returns:
trueif the given alias is associated with a key entry.
-
engineIsCertificateEntry
Indicates whether the specified alias is associated with aKeyStore.TrustedCertificateEntry.- Parameters:
alias- the alias of an entry.- Returns:
trueif the given alias is associated with a certificate entry.
-
engineGetCertificateAlias
Returns the alias associated with the first entry whose certificate matches the specified certificate.- Parameters:
cert- the certificate to find the associated entry's alias for.- Returns:
- the alias or
nullif no entry with the specified certificate can be found.
-
engineStore
public abstract void engineStore(OutputStream stream, char[] password) throws IOException, NoSuchAlgorithmException, CertificateExceptionWrites thisKeyStoreSpito the specifiedOutputStream. The data written to theOutputStreamis protected by the specified password.- Parameters:
stream- theOutputStreamto write the store's data to.password- the password to protect the data.- Throws:
IOException- if a problem occurred while writing to the stream.NoSuchAlgorithmException- if the required algorithm is not available.CertificateException- if the an exception occurred while storing the certificates of this codeKeyStoreSpi.
-
engineStore
public void engineStore(KeyStore.LoadStoreParameter param) throws IOException, NoSuchAlgorithmException, CertificateExceptionStores thisKeyStoreSpiusing the specifiedLoadStoreParameter.- Parameters:
param- theLoadStoreParameterthat specifies how to store thisKeyStoreSpi, maybenull.- Throws:
IOException- if a problem occurred while writing to the stream.NoSuchAlgorithmException- if the required algorithm is not available.CertificateException- if the an exception occurred while storing the certificates of this codeKeyStoreSpi.IllegalArgumentException- if the givenKeyStore.LoadStoreParameteris not recognized.
-
engineLoad
public abstract void engineLoad(InputStream stream, char[] password) throws IOException, NoSuchAlgorithmException, CertificateExceptionLoads thisKeyStoreSpifrom the givenInputStream. Utilizes the given password to verify the stored data.- Parameters:
stream- theInputStreamto load thisKeyStoreSpi's data from.password- the password to verify the stored data, maybenull.- Throws:
IOException- if a problem occurred while reading from the stream.NoSuchAlgorithmException- if the required algorithm is not available.CertificateException- if the an exception occurred while loading the certificates of this codeKeyStoreSpi.
-
engineLoad
public void engineLoad(KeyStore.LoadStoreParameter param) throws IOException, NoSuchAlgorithmException, CertificateExceptionLoads thisKeyStoreSpiusing the specifiedLoadStoreParameter.- Parameters:
param- theLoadStoreParameterthat specifies how to load thisKeyStoreSpi, maybenull.- Throws:
IOException- if a problem occurred while reading from the stream.NoSuchAlgorithmException- if the required algorithm is not available.CertificateException- if the an exception occurred while loading the certificates of this codeKeyStoreSpi.IllegalArgumentException- if the givenKeyStore.LoadStoreParameteris not recognized.
-
engineGetEntry
public KeyStore.Entry engineGetEntry(String alias, KeyStore.ProtectionParameter protParam) throws KeyStoreException, NoSuchAlgorithmException, UnrecoverableEntryExceptionReturns theEntrywith the given alias, using the specifiedProtectionParameter.- Parameters:
alias- the alias of the requested entry.protParam- theProtectionParameter, used to protect the requested entry, maybenull.- Returns:
- he
Entrywith the given alias, using the specifiedProtectionParameter. - Throws:
NoSuchAlgorithmException- if the required algorithm is not available.UnrecoverableEntryException- if the entry can not be recovered.KeyStoreException- if this operation fails
-
engineSetEntry
public void engineSetEntry(String alias, KeyStore.Entry entry, KeyStore.ProtectionParameter protParam) throws KeyStoreExceptionStores the givenEntryin thisKeyStoreSpiand associates the entry with the givenalias. The entry is protected by the specifiedProtectionParameter.If the specified alias already exists, it will be reassigned.
- Parameters:
alias- the alias for the entry.entry- the entry to store.protParam- theProtectionParameterto protect the entry.- Throws:
KeyStoreException- if this operation fails.
-
engineEntryInstanceOf
Indicates whether the entry for the given alias is assignable to the providedClass.- Parameters:
alias- the alias for the entry.entryClass- the type of the entry.- Returns:
trueif theEntryfor the alias is assignable to the specifiedentryClass.
-