FileDocCategorySizeDatePackage
Certificate.javaAPI DocJava SE 6 API8022Tue Jun 10 00:25:48 BST 2008java.security.cert

Certificate

public abstract class Certificate extends Object implements Serializable

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.

see
X509Certificate
see
CertificateFactory
author
Hemma Prafullchandra
version
1.27, 04/21/06

Fields Summary
private static final long
serialVersionUID
private final String
type
Constructors Summary
protected Certificate(String type)
Creates a certificate of the specified type.

param
type the standard name of the certificate type. See Appendix A in the Java Cryptography Architecture API Specification & Reference for information about standard certificate types.


                                               
       
	this.type = type;
    
Methods Summary
public booleanequals(java.lang.Object other)
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.

param
other the object to test for equality with this certificate.
return
true iff the encoded forms of the two certificates match, false otherwise.

        if (this == other) {
            return true;
	}
        if (!(other instanceof Certificate)) {
            return false;
	}
        try {
            byte[] thisCert = X509CertImpl.getEncodedInternal(this);
            byte[] otherCert = X509CertImpl.getEncodedInternal((Certificate)other);
	    
	    return Arrays.equals(thisCert, otherCert);
        } catch (CertificateException e) {
	    return false;
        }
    
public abstract byte[]getEncoded()
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.

return
the encoded form of this certificate
exception
CertificateEncodingException if an encoding error occurs.

public abstract java.security.PublicKeygetPublicKey()
Gets the public key from this certificate.

return
the public key.

public final java.lang.StringgetType()
Returns the type of this certificate.

return
the type of this certificate.

	return this.type;
    
public inthashCode()
Returns a hashcode value for this certificate from its encoded form.

return
the hashcode value.

        int retval = 0;
        try {
            byte[] certData = X509CertImpl.getEncodedInternal(this);
            for (int i = 1; i < certData.length; i++) {
                 retval += certData[i] * i;
            }
            return retval;
        } catch (CertificateException e) {
            return retval;
        }
    
public abstract java.lang.StringtoString()
Returns a string representation of this certificate.

return
a string representation of this certificate.

public abstract voidverify(java.security.PublicKey key)
Verifies that this certificate was signed using the private key that corresponds to the specified public key.

param
key the PublicKey used to carry out the verification.
exception
NoSuchAlgorithmException on unsupported signature algorithms.
exception
InvalidKeyException on incorrect key.
exception
NoSuchProviderException if there's no default provider.
exception
SignatureException on signature errors.
exception
CertificateException on encoding errors.

public abstract voidverify(java.security.PublicKey key, java.lang.String sigProvider)
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.

param
key the PublicKey used to carry out the verification.
param
sigProvider the name of the signature provider.
exception
NoSuchAlgorithmException on unsupported signature algorithms.
exception
InvalidKeyException on incorrect key.
exception
NoSuchProviderException on incorrect provider.
exception
SignatureException on signature errors.
exception
CertificateException on encoding errors.

protected java.lang.ObjectwriteReplace()
Replace the Certificate to be serialized.

return
the alternate Certificate object to be serialized
throws
java.io.ObjectStreamException if a new object representing this Certificate could not be created
since
1.3

	try {
	    return new CertificateRep(type, getEncoded());
	} catch (CertificateException e) {
	    throw new java.io.NotSerializableException
				("java.security.cert.Certificate: " +
				type +
				": " +
				e.getMessage());
	}