The TrustedCertificateEntry class

The KeyStore.TrustedCertificateEntry class definition is as follows:

public static final class KeyStore.TrustedCertificateEntry extends Object implements KeyStore.Entry

This class holds a trusted Certificate and has the following methods:

  • public Certificate getTrustedCertificate(): Returns the entry's trusted Certificate
  • public String toString(): Returns the entry's trusted Certificate as String

The key to using this class is understanding its flow. First, we must load KeyStore by using the getInstance method. Next, we must request access to the KeyStore instance. Then, we must gain access so that we can read and write to Object:

Keystore load-request-access pattern

The following code snippet shows the load-request-access implementation:

. . .
try {
// KeyStore implementation will be returned for the default type
KeyStore myKS = KeyStore.getInstance(KeyStore.getDefaultType());

// Load
myKS.load(null, null);

// Instantiate a KeyStore that holds a trusted certificate
TrustedCertificateEntry myCertEntry =
new TrustedCertificateEntry(generateCertificate());

// Assigns the trusted certificate to the "packt.pub" alias
myKS.setCertificateEntry("packt.pub",
myCertEntry.getTrustedCertificate());

return myKS;
}
catch (Exception e) {
throw new AssertionError(e);
}
}
. . .
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset