Package com.azure.security.keyvault.jca
Class KeyVaultKeyStore
java.lang.Object
java.security.KeyStoreSpi
com.azure.security.keyvault.jca.KeyVaultKeyStore
The Azure Key Vault implementation of the KeyStoreSpi.
- See Also:
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionLists all the alias names of this keystore.boolean
engineContainsAlias
(String alias) Checks if the given alias exists in this keystore.void
engineDeleteEntry
(String alias) Deletes the entry identified by the given alias from this keystore.boolean
engineEntryInstanceOf
(String alias, Class<? extends KeyStore.Entry> entryClass) Determines if the keystoreEntry
for the specifiedalias
is an instance or subclass of the specifiedentryClass
.engineGetCertificate
(String alias) Get the certificate associated with the given alias.Get the (alias) name of the first keystore entry whose certificate matches the given certificate.engineGetCertificateChain
(String alias) Get the certificate chain associated with the given alias.engineGetCreationDate
(String alias) Get the creation date of the entry identified by the given alias.engineGetEntry
(String alias, KeyStore.ProtectionParameter protParam) Gets aKeyStore.Entry
for the specified alias with the specified protection parameter.engineGetKey
(String alias, char[] password) Get key associated with the given alias.boolean
engineIsCertificateEntry
(String alias) Check whether the entry identified by the given alias contains a trusted certificate.boolean
engineIsKeyEntry
(String alias) Check whether the entry identified by the given alias is a key-related.void
engineLoad
(InputStream stream, char[] password) Loads the keystore from the given input stream.void
Loads the keystore using the givenKeyStore.LoadStoreParameter
.void
engineSetCertificateEntry
(String alias, Certificate certificate) Assigns the given certificate to the given alias.void
engineSetEntry
(String alias, KeyStore.Entry entry, KeyStore.ProtectionParameter protParam) Saves aKeyStore.Entry
under the specified alias.void
engineSetKeyEntry
(String alias, byte[] key, Certificate[] chain) Assigns the given key (that has already been protected) to the given alias.void
engineSetKeyEntry
(String alias, Key key, char[] password, Certificate[] chain) Assigns the given key to the given alias, protecting it with the given password.int
Retrieves the number of entries in this keystore.void
engineStore
(OutputStream stream, char[] password) Stores this keystore to the given output stream, and protects its integrity with the given password.void
Stores this keystore using the given.static KeyStore
get key vault key store by system propertyMethods inherited from class java.security.KeyStoreSpi
engineGetAttributes, engineProbe
-
Field Details
-
KEY_STORE_TYPE
Stores the key-store name.- See Also:
-
ALGORITHM_NAME
Stores the algorithm name.- See Also:
-
-
Constructor Details
-
KeyVaultKeyStore
public KeyVaultKeyStore()Constructor.The constructor uses System.getProperty for
azure.keyvault.uri
,azure.keyvault.aadAuthenticationUrl
,azure.keyvault.tenantId
,azure.keyvault.clientId
,azure.keyvault.clientSecret
andazure.keyvault.managedIdentity
to initialize the Key Vault client.
-
-
Method Details
-
getKeyVaultKeyStoreBySystemProperty
public static KeyStore getKeyVaultKeyStoreBySystemProperty() throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOExceptionget key vault key store by system property- Returns:
- KeyVault key store
- Throws:
CertificateException
- if any of the certificates in the keystore could not be loadedNoSuchAlgorithmException
- when algorithm is unavailable.KeyStoreException
- when no Provider supports a KeyStoreSpi implementation for the specified typeIOException
- when an I/O error occurs.
-
engineAliases
Lists all the alias names of this keystore.- Specified by:
engineAliases
in classKeyStoreSpi
- Returns:
- enumeration of the alias names
-
engineContainsAlias
Checks if the given alias exists in this keystore.- Specified by:
engineContainsAlias
in classKeyStoreSpi
- Parameters:
alias
- the alias name- Returns:
- true if the alias exists, false otherwise
-
engineDeleteEntry
Deletes the entry identified by the given alias from this keystore.- Specified by:
engineDeleteEntry
in classKeyStoreSpi
- Parameters:
alias
- the alias name
-
engineEntryInstanceOf
Determines if the keystoreEntry
for the specifiedalias
is an instance or subclass of the specifiedentryClass
.- Overrides:
engineEntryInstanceOf
in classKeyStoreSpi
- Parameters:
alias
- the alias nameentryClass
- the entry class- Returns:
- true if the keystore
Entry
for the specifiedalias
is an instance or subclass of the specifiedentryClass
, false otherwise
-
engineGetCertificate
Get the certificate associated with the given alias.- Specified by:
engineGetCertificate
in classKeyStoreSpi
- Parameters:
alias
- the alias name- Returns:
- the certificate, or null if the given alias does not exist or does not contain a certificate
-
engineGetCertificateAlias
Get the (alias) name of the first keystore entry whose certificate matches the given certificate.- Specified by:
engineGetCertificateAlias
in classKeyStoreSpi
- Parameters:
cert
- the certificate to match with.- Returns:
- the alias name of the first entry with matching certificate, or null if no such entry exists in this keystore
-
engineGetCertificateChain
Get the certificate chain associated with the given alias.- Specified by:
engineGetCertificateChain
in classKeyStoreSpi
- Parameters:
alias
- the alias name- Returns:
- the certificate chain (ordered with the user's certificate first and the root certificate authority last), or null if the given alias does not exist or does not contain a certificate chain
-
engineGetCreationDate
Get the creation date of the entry identified by the given alias.- Specified by:
engineGetCreationDate
in classKeyStoreSpi
- Parameters:
alias
- the alias name- Returns:
- the creation date of this entry, or null if the given alias does not exist
-
engineGetEntry
public KeyStore.Entry engineGetEntry(String alias, KeyStore.ProtectionParameter protParam) throws KeyStoreException, NoSuchAlgorithmException, UnrecoverableEntryException Gets aKeyStore.Entry
for the specified alias with the specified protection parameter.- Overrides:
engineGetEntry
in classKeyStoreSpi
- Parameters:
alias
- the alias nameprotParam
- the protParam- Returns:
- the
KeyStore.Entry
for the specified alias,ornull
if there is no such entry - Throws:
KeyStoreException
- if the operation failedNoSuchAlgorithmException
- if the algorithm for recovering the entry cannot be foundUnrecoverableEntryException
- if the specifiedprotParam
were insufficient or invalid
-
engineGetKey
Get key associated with the given alias.- Specified by:
engineGetKey
in classKeyStoreSpi
- Parameters:
alias
- the alias namepassword
- the password for recovering the key- Returns:
- the requested key, or null if the given alias does not exist or does not identify a key-related entry
-
engineIsCertificateEntry
Check whether the entry identified by the given alias contains a trusted certificate.- Specified by:
engineIsCertificateEntry
in classKeyStoreSpi
- Parameters:
alias
- the alias name- Returns:
- true if the entry identified by the given alias contains a trusted certificate, false otherwise
-
engineIsKeyEntry
Check whether the entry identified by the given alias is a key-related.- Specified by:
engineIsKeyEntry
in classKeyStoreSpi
- Parameters:
alias
- the alias for the keystore entry to be checked- Returns:
- true if the entry identified by the given alias is a key-related, false otherwise
-
engineLoad
Loads the keystore using the givenKeyStore.LoadStoreParameter
.- Overrides:
engineLoad
in classKeyStoreSpi
- Parameters:
param
- theKeyStore.LoadStoreParameter
that specifies how to load the keystore, which may benull
-
engineLoad
Loads the keystore from the given input stream.- Specified by:
engineLoad
in classKeyStoreSpi
- Parameters:
stream
- the input stream from which the keystore is loaded,ornull
password
- the password
-
engineSetCertificateEntry
Assigns the given certificate to the given alias.- Specified by:
engineSetCertificateEntry
in classKeyStoreSpi
- Parameters:
alias
- the alias namecertificate
- the certificate
-
engineSetEntry
public void engineSetEntry(String alias, KeyStore.Entry entry, KeyStore.ProtectionParameter protParam) throws KeyStoreException Saves aKeyStore.Entry
under the specified alias. The specified protection parameter is used to protect theEntry
.- Overrides:
engineSetEntry
in classKeyStoreSpi
- Parameters:
alias
- the alias nameentry
- the entryprotParam
- the protParam- Throws:
KeyStoreException
- if this operation fails
-
engineSetKeyEntry
Assigns the given key to the given alias, protecting it with the given password.- Specified by:
engineSetKeyEntry
in classKeyStoreSpi
- Parameters:
alias
- the alias namekey
- the key to be associated with the aliaspassword
- the password to protect the keychain
- the certificate chain
-
engineSetKeyEntry
Assigns the given key (that has already been protected) to the given alias.- Specified by:
engineSetKeyEntry
in classKeyStoreSpi
- Parameters:
alias
- the alias namekey
- the keychain
- the certificate chain
-
engineSize
public int engineSize()Retrieves the number of entries in this keystore.- Specified by:
engineSize
in classKeyStoreSpi
- Returns:
- the number of entries in this keystore
-
engineStore
Stores this keystore to the given output stream, and protects its integrity with the given password.- Specified by:
engineStore
in classKeyStoreSpi
- Parameters:
stream
- the output stream to which this keystore is writtenpassword
- the password to generate the keystore integrity check
-
engineStore
Stores this keystore using the given.- Overrides:
engineStore
in classKeyStoreSpi
- Parameters:
param
- the param
-