CertSource

public class CertSource

This class loads a X509 certificate file. Basically this class only acts as a convenience wrapper of java.security.cert.X509Certificate.

Author:kcyee

Fields

x509Cert

protected X509Certificate x509Cert

internal X509 certificate storage.

Constructors

CertSource

public CertSource()

Default constructor. The user should call load() to further initialize the certificate.

CertSource

public CertSource(File certFile)

Constructor with initialization parameters. The certificate will be loaded from the file specified.

Parameters:
  • certFile – the certificate file
Throws:
  • CertificateException – if the file specified cannot be read, or any errors occurred when loading the file.

CertSource

public CertSource(String certFile)

Constructor with initialization parameters. The certificate will be loaded from the file specified.

Parameters:
  • certFile – the file name of the certificate file
Throws:
  • CertificateException – if the file specified cannot be read, or any errors occurred when loading the file.

CertSource

public CertSource(X509Certificate cert)

Constructor with initialization parameters. The class will be initialized with the specified certificate.

Parameters:
  • cert – the preloaded certificate

Methods

getInternalCert

public X509Certificate getInternalCert()

Gets the X509Certificate stored internally.

Returns:the X509Certificate stored internally.

getIssuer

public String getIssuer()

Gets the distinguished name (DN) of the issuer of the certificate.

Throws:
Returns:

the DN of the issuer

getPublicKey

public PublicKey getPublicKey()

Gets the public key in this certificate.

Returns:the public key in this certificate.

isValid

public boolean isValid()

Checks whether the certificate is valid in current time.

Returns:true if the certificate is still valid, false if otherwise.

isValid

public boolean isValid(Date d)

Checks whether the certificate is valid in the specified time.

Parameters:
  • d – the specified time
Returns:

true if the certificate is valid, false if otherwise.

load

public void load(File certFile)

Loads the certificate file.

Parameters:
  • certFile – the certificate file
Throws:
  • CertificateException – if the file specified cannot be read, or any errors occurred when loading the file.

load

public void load(String certFile)

Loads the certificate file.

Parameters:
  • certFile – the file name of the certificate file
Throws:
  • CertificateException – if the file specified cannot be read, or any errors occurred when loading the file.

verify

public boolean verify(PublicKey pubKey)

Verifies whether the certificate is signed by the private key corresponding to the specified public key.

Parameters:
  • pubKey – the public key for verification
Returns:

true if the verification is passed, false if otherwise.

verify

public boolean verify(Certificate cert)

Verifies whether the certificate is signed by the private key corresponding to public key in the specified certificate.

Parameters:
  • cert – the certificate for verification
Returns:

true if the verification is passed, false if otherwise.

verify

public boolean verify(CertSource cert)

Verifies whether the certificate is signed by the private key corresponding to public key in the specified certificate.

Parameters:
  • cert – the certificate for verification
Returns:

true if the verification is passed, false if otherwise.