FileDocCategorySizeDatePackage
Certificate.javaAPI DocAndroid 1.5 API9434Wed May 06 22:41:06 BST 2009java.security.cert

Certificate

public abstract class Certificate extends Object implements Serializable
Abstract class to represent identity certificates. It represents a way to verify the binding of a Principal and its public key. Examples are X.509, PGP, and SDSI.
since
Android 1.0

Fields Summary
private static final long
serialVersionUID
private final String
type
Constructors Summary
protected Certificate(String type)
Creates a new {@code Certificate} with the specified type.

param
type the certificate type.
since
Android 1.0


                                  
       
        this.type = type;
    
Methods Summary
public booleanequals(java.lang.Object other)
Compares the argument to the certificate, and returns {@code true} if they represent the same object using a class specific comparison. The implementation in Object returns {@code true} only if the argument is the exact same object as the callee (==).

param
other the object to compare with this object.
return
{@code true} if the object is the same as this object, {@code false} if it is different from this object.
see
#hashCode
since
Android 1.0

        // obj equal to itself
        if (this == other) {
            return true;
        }
        if (other instanceof Certificate) {
            try {
                // check that encoded forms match
                return Arrays.equals(this.getEncoded(),
                        ((Certificate)other).getEncoded());
            } catch (CertificateEncodingException e) {
                throw new RuntimeException(e);
            }
        }
        return false;
    
public abstract byte[]getEncoded()
Returns the encoded representation for this certificate.

return
the encoded representation for this certificate.
throws
CertificateEncodingException if the encoding fails.
since
Android 1.0

public abstract java.security.PublicKeygetPublicKey()
Returns the public key corresponding to this certificate.

return
the public key corresponding to this certificate.
since
Android 1.0

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

return
the certificate type.
since
Android 1.0

        return type;
    
public inthashCode()
Returns an integer hash code for the certificate. Any two objects which return {@code true} when passed to {@code equals} must return the same value for this method.

return
the certificate's hash
see
#equals
since
Android 1.0

        try {
            byte[] encoded = getEncoded();
            int hash = 0;
            for (int i=0; i<encoded.length; i++) {
                hash += i*encoded[i];
            }
            return hash;
        } catch (CertificateEncodingException e) {
            throw new RuntimeException(e);
        }
    
public abstract java.lang.StringtoString()
Returns a string containing a concise, human-readable description of the certificate.

return
a printable representation for the certificate.
since
Android 1.0

public abstract voidverify(java.security.PublicKey key)
Verifies that this certificate was signed with the given public key.

param
key PublicKey public key for which verification should be performed.
throws
CertificateException if encoding errors are detected.
throws
NoSuchAlgorithmException if an unsupported algorithm is detected.
throws
InvalidKeyException if an invalid key is detected.
throws
NoSuchProviderException if there is no default provider.
throws
SignatureException if signature errors are detected.
since
Android 1.0

public abstract voidverify(java.security.PublicKey key, java.lang.String sigProvider)
Verifies that this certificate was signed with the given public key. It Uses the signature algorithm given by the provider.

param
key PublicKey public key for which verification should be performed.
param
sigProvider String the name of the signature provider.
exception
CertificateException if encoding errors are detected.
exception
NoSuchAlgorithmException if an unsupported algorithm is detected.
exception
InvalidKeyException if an invalid key is detected.
exception
NoSuchProviderException if the specified provider does not exists.
exception
SignatureException if signature errors are detected.
since
Android 1.0

protected java.lang.ObjectwriteReplace()
Returns an alternate object to be serialized.

return
the object to serialize.
throws
ObjectStreamException if the creation of the alternate object fails.
since
Android 1.0

        try {
            return new CertificateRep(getType(), getEncoded());
        } catch (CertificateEncodingException e) {  
            throw new NotSerializableException (
                    Messages.getString("security.66", e)); //$NON-NLS-1$
        }