Top Description Inners Fields Constructors Methods
java.security.cert

public abstract Class Certificate

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Known Direct Subclasses
java.security.cert.X509Certificate
Imports
java.util.Arrays, java.security.Provider, .PublicKey, .NoSuchAlgorithmException, .NoSuchProviderException, .InvalidKeyException, .SignatureException, sun.security.x509.X509CertImpl

Abstract class for managing a variety of identity certificates. An identity certificate is a binding of a principal to a public key which is vouched for by another principal. (A principal represents an entity such as an individual user, a group, or a corporation.)

This class is an abstraction for certificates that have different formats but important common uses. For example, different types of certificates, such as X.509 and PGP, share general certificate functionality (like encoding and verifying) and some types of information (like a public key).

X.509, PGP, and SDSI certificates can all be implemented by subclassing the Certificate class, even though they contain different sets of information, and they store and retrieve the information in different ways.

Author
Hemma Prafullchandra
Since
1.2
See Also
X509Certificate, CertificateFactory

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class
Certificate.CertificateRep

Alternate Certificate class for serialization.

Field Summary

Modifier and TypeField and Description
private transient int
hash

The hash code for the certificate.

private static final long
private final transient String
type

The certificate type.

Constructor Summary

AccessConstructor and Description
protected
Certificate(String
the standard name of the certificate type. See the CertificateFactory section in the Java Security Standard Algorithm Names Specification for information about standard certificate types.
type
)

Creates a certificate of the specified type.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true iff the encoded forms of the two certificates match, false otherwise.
equals
(Object
the object to test for equality with this certificate.
other
)

Overrides java.lang.Object.equals.

Compares this certificate for equality with the specified object.

public abstract byte[]

Returns:

the encoded form of this certificate
getEncoded
()

Returns the encoded form of this certificate.

public abstract PublicKey

Returns:

the public key.
getPublicKey
()

Gets the public key from this certificate.

public final String

Returns:

the type of this certificate.
getType
()

Returns the type of this certificate.

public int

Returns:

the hashcode value for this certificate from its encoded form
hashCode
()

Overrides java.lang.Object.hashCode.

Returns the hashcode value for this certificate from its encoded form.

public abstract String

Returns:

a string representation of this certificate.
toString
()

Overrides java.lang.Object.toString.

Returns a string representation of this certificate.

public abstract void
verify(PublicKey
the PublicKey used to carry out the verification.
key
)

Verifies that this certificate was signed using the private key that corresponds to the specified public key.

public abstract void
verify(PublicKey
the PublicKey used to carry out the verification.
key
,
String
the name of the signature provider.
sigProvider
)

Verifies that this certificate was signed using the private key that corresponds to the specified public key.

public void
verify(PublicKey
the PublicKey used to carry out the verification.
key
,
Provider
the signature provider.
sigProvider
)

Verifies that this certificate was signed using the private key that corresponds to the specified public key.

protected Object

Returns:

a CertificateRep object containing the type and encoded bytes of the Certificate
writeReplace
()

Replace the Certificate to be serialized with a CertificateRep object containing the type and encoded bytes of the Certificate.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

hashback to summary
private transient int hash

The hash code for the certificate.

serialVersionUIDback to summary
private static final long serialVersionUID
Annotations
@Serial
typeback to summary
private final transient String type

The certificate type.

Constructor Detail

Certificateback to summary
protected Certificate(String type)

Creates a certificate of the specified type.

Parameters
type:String

the standard name of the certificate type. See the CertificateFactory section in the Java Security Standard Algorithm Names Specification for information about standard certificate types.

Method Detail

equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

Compares this certificate for equality with the specified object. If the other object is an instanceof Certificate, then its encoded form is retrieved and compared with the encoded form of this certificate.

Parameters
other:Object

the object to test for equality with this certificate.

Returns:boolean

true iff the encoded forms of the two certificates match, false otherwise.

Annotations
@Override
getEncodedback to summary
public abstract byte[] getEncoded() throws CertificateEncodingException

Returns the encoded form of this certificate. It is assumed that each certificate type would have only a single form of encoding; for example, X.509 certificates would be encoded as ASN.1 DER.

Returns:byte[]

the encoded form of this certificate

Exceptions
CertificateEncodingException:
if an encoding error occurs.
getPublicKeyback to summary
public abstract PublicKey getPublicKey()

Gets the public key from this certificate.

Returns:PublicKey

the public key.

getTypeback to summary
public final String getType()

Returns the type of this certificate.

Returns:String

the type of this certificate.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Returns the hashcode value for this certificate from its encoded form.

Returns:int

the hashcode value for this certificate from its encoded form

Annotations
@Override
toStringback to summary
public abstract String toString()

Overrides java.lang.Object.toString.

Returns a string representation of this certificate.

Returns:String

a string representation of this certificate.

verifyback to summary
public abstract void verify(PublicKey key) throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException

Verifies that this certificate was signed using the private key that corresponds to the specified public key.

Parameters
key:PublicKey

the PublicKey used to carry out the verification.

Exceptions
CertificateException:
on encoding errors.
NoSuchAlgorithmException:
on unsupported signature algorithms.
InvalidKeyException:
on incorrect key.
NoSuchProviderException:
if there's no default provider.
SignatureException:
on signature errors.
verifyback to summary
public abstract void verify(PublicKey key, String sigProvider) throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException

Verifies that this certificate was signed using the private key that corresponds to the specified public key. This method uses the signature verification engine supplied by the specified provider.

Parameters
key:PublicKey

the PublicKey used to carry out the verification.

sigProvider:String

the name of the signature provider.

Exceptions
CertificateException:
on encoding errors.
NoSuchAlgorithmException:
on unsupported signature algorithms.
InvalidKeyException:
on incorrect key.
NoSuchProviderException:
on incorrect provider.
SignatureException:
on signature errors.
verifyback to summary
public void verify(PublicKey key, Provider sigProvider) throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, SignatureException

Verifies that this certificate was signed using the private key that corresponds to the specified public key. This method uses the signature verification engine supplied by the specified provider. Note that the specified Provider object does not have to be registered in the provider list.

This method was added to version 1.8 of the Java Platform Standard Edition. In order to maintain backwards compatibility with existing service providers, this method cannot be abstract and by default throws an UnsupportedOperationException.

Parameters
key:PublicKey

the PublicKey used to carry out the verification.

sigProvider:Provider

the signature provider.

Exceptions
CertificateException:
on encoding errors.
NoSuchAlgorithmException:
on unsupported signature algorithms.
InvalidKeyException:
on incorrect key.
SignatureException:
on signature errors.
UnsupportedOperationException:
if the method is not supported
Since
1.8
writeReplaceback to summary
protected Object writeReplace() throws ObjectStreamException

Replace the Certificate to be serialized with a CertificateRep object containing the type and encoded bytes of the Certificate.

Returns:Object

a CertificateRep object containing the type and encoded bytes of the Certificate

Annotations
@Serial
Exceptions
ObjectStreamException:
if a CertificateRep object representing this Certificate could not be created
Since
1.3
java.security.cert back to summary

protected Class Certificate.CertificateRep

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable

Alternate Certificate class for serialization.
Since
1.3

Field Summary

Modifier and TypeField and Description
private final byte[]
data

The certificate data.

private static final long
private final String
type

The standard name of the certificate type.

Constructor Summary

AccessConstructor and Description
protected
CertificateRep(String
the standard name of the Certificate type.
type
,
byte[]
the Certificate data.
data
)

Construct the alternate Certificate class with the Certificate type and Certificate encoding bytes.

Method Summary

Modifier and TypeMethod and Description
protected Object

Returns:

the resolved Certificate object
readResolve
()

Returns a Certificate with the type and data of this CertificateRep.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

databack to summary
private final byte[] data

The certificate data.

serialVersionUIDback to summary
private static final long serialVersionUID
Annotations
@Serial
typeback to summary
private final String type

The standard name of the certificate type.

Constructor Detail

CertificateRepback to summary
protected CertificateRep(String type, byte[] data)

Construct the alternate Certificate class with the Certificate type and Certificate encoding bytes.

Parameters
type:String

the standard name of the Certificate type.

data:byte[]

the Certificate data.

Method Detail

readResolveback to summary
protected Object readResolve() throws ObjectStreamException

Returns a Certificate with the type and data of this CertificateRep.

Returns:Object

the resolved Certificate object

Annotations
@Serial
Exceptions
ObjectStreamException:
if the Certificate could not be resolved