Class PKCS12KeyStoreSpi

java.lang.Object
java.security.KeyStoreSpi
org.bouncycastle.jcajce.provider.keystore.pkcs12.PKCS12KeyStoreSpi
All Implemented Interfaces:
PKCSObjectIdentifiers, X509ObjectIdentifiers, BCKeyStore
Direct Known Subclasses:
PKCS12KeyStoreSpi.BCPKCS12KeyStore

public class PKCS12KeyStoreSpi
extends KeyStoreSpi
implements PKCSObjectIdentifiers, X509ObjectIdentifiers, BCKeyStore
  • Field Details

  • Constructor Details

  • Method Details

    • setRandom

      public void setRandom​(SecureRandom rand)
      Description copied from interface: BCKeyStore
      set the random source for the key store
      Specified by:
      setRandom in interface BCKeyStore
    • engineAliases

      public Enumeration engineAliases()
      Description copied from class: KeyStoreSpi
      Returns an Enumeration over all alias names stored in this KeyStoreSpi.
      Specified by:
      engineAliases in class KeyStoreSpi
      Returns:
      an Enumeration over all alias names stored in this KeyStoreSpi.
    • engineContainsAlias

      public boolean engineContainsAlias​(String alias)
      Description copied from class: KeyStoreSpi
      Indicates whether the given alias is present in this KeyStoreSpi.
      Specified by:
      engineContainsAlias in class KeyStoreSpi
      Parameters:
      alias - the alias of an entry.
      Returns:
      true if the alias exists, false otherwise.
    • engineDeleteEntry

      public void engineDeleteEntry​(String alias) throws KeyStoreException
      this is not quite complete - we should follow up on the chain, a bit tricky if a certificate appears in more than one chain...
      Specified by:
      engineDeleteEntry in class KeyStoreSpi
      Parameters:
      alias - the alias for the entry.
      Throws:
      KeyStoreException - if the entry can not be deleted.
    • engineGetCertificate

      public Certificate engineGetCertificate​(String alias)
      simply return the cert for the private key
      Specified by:
      engineGetCertificate in class KeyStoreSpi
      Parameters:
      alias - the alias for the entry.
      Returns:
      the trusted certificate for the entry with the given alias, or null if the specified alias is not bound to an entry.
    • engineGetCertificateAlias

      public String engineGetCertificateAlias​(Certificate cert)
      Description copied from class: KeyStoreSpi
      Returns the alias associated with the first entry whose certificate matches the specified certificate.
      Specified by:
      engineGetCertificateAlias in class KeyStoreSpi
      Parameters:
      cert - the certificate to find the associated entry's alias for.
      Returns:
      the alias or null if no entry with the specified certificate can be found.
    • engineGetCertificateChain

      public Certificate[] engineGetCertificateChain​(String alias)
      Description copied from class: KeyStoreSpi
      Returns the certificate chain for the entry with the given alias.
      Specified by:
      engineGetCertificateChain in class KeyStoreSpi
      Parameters:
      alias - the alias for the entry
      Returns:
      the certificate chain for the entry with the given alias, or null if the specified alias is not bound to an entry.
    • engineGetCreationDate

      public Date engineGetCreationDate​(String alias)
      Description copied from class: KeyStoreSpi
      Returns the creation date of the entry with the given alias.
      Specified by:
      engineGetCreationDate in class KeyStoreSpi
      Parameters:
      alias - the alias for the entry.
      Returns:
      the creation date, or null if the specified alias is not bound to an entry.
    • engineGetKey

      public Key engineGetKey​(String alias, char[] password) throws NoSuchAlgorithmException, UnrecoverableKeyException
      Description copied from class: KeyStoreSpi
      Returns the key with the given alias, using the password to recover the key from the store.
      Specified by:
      engineGetKey in class KeyStoreSpi
      Parameters:
      alias - the alias for the entry.
      password - the password used to recover the key.
      Returns:
      the key with the specified alias, or null if 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.
    • engineIsCertificateEntry

      public boolean engineIsCertificateEntry​(String alias)
      Description copied from class: KeyStoreSpi
      Indicates whether the specified alias is associated with a KeyStore.TrustedCertificateEntry.
      Specified by:
      engineIsCertificateEntry in class KeyStoreSpi
      Parameters:
      alias - the alias of an entry.
      Returns:
      true if the given alias is associated with a certificate entry.
    • engineIsKeyEntry

      public boolean engineIsKeyEntry​(String alias)
      Description copied from class: KeyStoreSpi
      Indicates whether the specified alias is associated with either a KeyStore.PrivateKeyEntry or a KeyStore.SecretKeyEntry.
      Specified by:
      engineIsKeyEntry in class KeyStoreSpi
      Parameters:
      alias - the alias of an entry.
      Returns:
      true if the given alias is associated with a key entry.
    • engineSetCertificateEntry

      public void engineSetCertificateEntry​(String alias, Certificate cert) throws KeyStoreException
      Description copied from class: KeyStoreSpi
      Associates the given alias with a certificate.

      If the specified alias already exists, it will be reassigned.

      Specified by:
      engineSetCertificateEntry in class KeyStoreSpi
      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.
    • engineSetKeyEntry

      public void engineSetKeyEntry​(String alias, byte[] key, Certificate[] chain) throws KeyStoreException
      Description copied from class: KeyStoreSpi
      Associates the given alias with a key and a certificate chain.

      If the specified alias already exists, it will be reassigned.

      Specified by:
      engineSetKeyEntry in class KeyStoreSpi
      Parameters:
      alias - the alias for the key.
      key - the key in an encoded format.
      chain - the certificate chain.
      Throws:
      KeyStoreException - if this operation fails.
    • engineSetKeyEntry

      public void engineSetKeyEntry​(String alias, Key key, char[] password, Certificate[] chain) throws KeyStoreException
      Description copied from class: KeyStoreSpi
      Associates the given alias with the key, password and certificate chain.

      If the specified alias already exists, it will be reassigned.

      Specified by:
      engineSetKeyEntry in class KeyStoreSpi
      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.
    • engineSize

      public int engineSize()
      Description copied from class: KeyStoreSpi
      Returns the number of entries stored in this KeyStoreSpi.
      Specified by:
      engineSize in class KeyStoreSpi
      Returns:
      the number of entries stored in this KeyStoreSpi.
    • unwrapKey

      protected PrivateKey unwrapKey​(AlgorithmIdentifier algId, byte[] data, char[] password, boolean wrongPKCS12Zero) throws IOException
      Throws:
      IOException
    • wrapKey

      protected byte[] wrapKey​(String algorithm, Key key, PKCS12PBEParams pbeParams, char[] password) throws IOException
      Throws:
      IOException
    • cryptData

      protected byte[] cryptData​(boolean forEncryption, AlgorithmIdentifier algId, char[] password, boolean wrongPKCS12Zero, byte[] data) throws IOException
      Throws:
      IOException
    • engineLoad

      public void engineLoad​(InputStream stream, char[] password) throws IOException
      Description copied from class: KeyStoreSpi
      Loads this KeyStoreSpi from the given InputStream. Utilizes the given password to verify the stored data.
      Specified by:
      engineLoad in class KeyStoreSpi
      Parameters:
      stream - the InputStream to load this KeyStoreSpi's data from.
      password - the password to verify the stored data, maybe null.
      Throws:
      IOException - if a problem occurred while reading from the stream.
    • engineStore

      Description copied from class: KeyStoreSpi
      Stores this KeyStoreSpi using the specified LoadStoreParameter.
      Overrides:
      engineStore in class KeyStoreSpi
      Parameters:
      param - the LoadStoreParameter that specifies how to store this KeyStoreSpi, maybe null.
      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 code KeyStoreSpi.
    • engineStore

      public void engineStore​(OutputStream stream, char[] password) throws IOException
      Description copied from class: KeyStoreSpi
      Writes this KeyStoreSpi to the specified OutputStream. The data written to the OutputStream is protected by the specified password.
      Specified by:
      engineStore in class KeyStoreSpi
      Parameters:
      stream - the OutputStream to write the store's data to.
      password - the password to protect the data.
      Throws:
      IOException - if a problem occurred while writing to the stream.