Class XmlCertVault

java.lang.Object
com.chilkatsoft.chilkat2.ChilkatObject
com.chilkatsoft.chilkat2.XmlCertVault
All Implemented Interfaces:
AutoCloseable

public class XmlCertVault extends ChilkatObject
<section class="xmlcertvault-summary">

Collect certificates, certificate chains, PEM data, and PFX private keys in an XML vault.

Chilkat.XmlCertVault stores certificates and private-key material in a portable XML-based certificate vault. It can add individual certificates, certificate chains, DER or encoded certificates, PEM files, certificate strings, and PFX/PKCS12 data from files, memory, encoded text, or existing Chilkat objects. The vault can then be exported as XML, loaded from XML, or saved to an XML file for later reuse by other Chilkat certificate and TLS workflows.

Add certificates

Add certificates from Cert objects, files, PEM strings, binary DER bytes, or encoded data such as Base64 or hex.

Add certificate chains

Import an entire CertChain when related issuer and intermediate certificates should be kept together in the vault.

Add PEM content

Load PEM files containing one or more certificates and/or private keys, including encrypted PEM content when a password is supplied.

Add PFX / PKCS12

Add PFX data from a Pfx object, file, byte array, or encoded string, using the PFX password to import private-key material.

Master password protection

Use MasterPassword to protect access to private keys stored in the vault.

Load and save XML

Export the vault with GetXml, load it with LoadXml or LoadXmlFile, and persist it with SaveXml.

Common pattern: Create an XmlCertVault, set MasterPassword when the vault will contain private keys, add certificates or PFX/PEM material, then save the vault with SaveXml or keep the XML string from GetXml. Later, reload the same vault with LoadXml or LoadXmlFile and provide the same master password before using private keys.

Security note: Certificates are stored unencrypted, but private keys are stored using 256-bit AES encryption. The individual PFX passwords are also stored encrypted with the vault's MasterPassword, which is required to access any private keys contained in the XML vault.

</section>

Instances hold a native Chilkat object: close them with ChilkatObject.close() (try-with-resources) when done; an unclosed instance is freed when it becomes unreachable.

See Also:
Online reference
  • Constructor Details

    • XmlCertVault

      public XmlCertVault()
      Creates a new XmlCertVault object.
  • Method Details

    • getMasterPassword

      public String getMasterPassword()
      The master password for the vault. Certificates are stored unencrypted, but private keys are stored 256-bit AES encrypted using the individual PFX passwords. The PFX passwords are stored 256-bit AES encrypted using the master password. The master password is required to acces any of the private keys stored within the XML vault.
      Returns:
      the value of the MasterPassword property
    • setMasterPassword

      public void setMasterPassword​(String value)
      Sets the MasterPassword property; see getMasterPassword().
      Parameters:
      value - the new value (not null)
    • addCert

      public void addCert​(Cert cert)
      Adds a certificate to the XML vault.
      Parameters:
      cert - the cert argument (not null)
      Throws:
      ChilkatException - if the operation fails; ChilkatException.getLastErrorText() says why
    • addCertChain

      public void addCertChain​(CertChain certChain)
      Adds a chain of certificates to the XML vault.
      Parameters:
      certChain - the certChain argument (not null)
      Throws:
      ChilkatException - if the operation fails; ChilkatException.getLastErrorText() says why
    • addCertEncoded

      public void addCertEncoded​(String encodedBytes, String encoding)
      Adds a certificate to the XML vault where certificate is passed directly from encoded bytes (such as Base64, Hex, etc.). The encoding is indicated by encoding.
      Parameters:
      encodedBytes - the encodedBytes argument (not null)
      encoding - the encoding argument (not null)
      Throws:
      ChilkatException - if the operation fails; ChilkatException.getLastErrorText() says why
    • addCertFile

      public void addCertFile​(String path)
      Adds a certificate to the XML vault.
      Parameters:
      path - the path argument (not null)
      Throws:
      ChilkatException - if the operation fails; ChilkatException.getLastErrorText() says why
    • addCertString

      public void addCertString​(String certData)
      Adds a certificate from any string representation format such as PEM.
      Parameters:
      certData - the certData argument (not null)
      Throws:
      ChilkatException - if the operation fails; ChilkatException.getLastErrorText() says why
    • addPemFile

      public void addPemFile​(String path, String password)
      Adds the contents of a PEM file to the XML vault. The PEM file may be encrypted, and it may contain one or more certificates and/or private keys. The password is optional and only required if the PEM file contains encrypted content that requires a password.
      Parameters:
      path - the path argument (not null)
      password - the password argument (not null)
      Throws:
      ChilkatException - if the operation fails; ChilkatException.getLastErrorText() says why
    • addPfx

      public void addPfx​(Pfx pfx)
      Adds a PFX (PKCS12) to the XML vault.
      Parameters:
      pfx - the pfx argument (not null)
      Throws:
      ChilkatException - if the operation fails; ChilkatException.getLastErrorText() says why
    • addPfxEncoded

      public void addPfxEncoded​(String encodedBytes, String encoding, String password)
      Adds a PFX to the XML vault where PFX is passed directly from encoded bytes (such as Base64, Hex, etc.). The encoding is indicated by encoding.
      Parameters:
      encodedBytes - the encodedBytes argument (not null)
      encoding - the encoding argument (not null)
      password - the password argument (not null)
      Throws:
      ChilkatException - if the operation fails; ChilkatException.getLastErrorText() says why
    • addPfxFile

      public void addPfxFile​(String path, String password)
      Adds a PFX file to the XML vault.
      Parameters:
      path - the path argument (not null)
      password - the password argument (not null)
      Throws:
      ChilkatException - if the operation fails; ChilkatException.getLastErrorText() says why
    • getXml

      public String getXml()
      Returns the contents of the cert vault as an XML string.
      Returns:
      the result (never null)
      Throws:
      ChilkatException - if the operation fails; ChilkatException.getLastErrorText() says why
    • loadXml

      public void loadXml​(String xml)
      Loads from an XML string.
      Parameters:
      xml - the xml argument (not null)
      Throws:
      ChilkatException - if the operation fails; ChilkatException.getLastErrorText() says why
    • loadXmlFile

      public void loadXmlFile​(String path)
      Loads from an XML file.
      Parameters:
      path - the path argument (not null)
      Throws:
      ChilkatException - if the operation fails; ChilkatException.getLastErrorText() says why
    • saveXml

      public void saveXml​(String path)
      Saves the contents to an XML file.
      Parameters:
      path - the path argument (not null)
      Throws:
      ChilkatException - if the operation fails; ChilkatException.getLastErrorText() says why