FileDocCategorySizeDatePackage
X509CertificateStringifier.javaAPI DocGlassfish v2 API4247Fri May 04 22:31:08 BST 2007com.sun.appserv.management.util.stringifier

X509CertificateStringifier

public final class X509CertificateStringifier extends Object implements Stringifier
Stringifies an X509CertificateStringifier.

Fields Summary
public static final X509CertificateStringifier
DEFAULT
Constructors Summary
public X509CertificateStringifier()

	
		
	
	
	
Methods Summary
private static byte[]getFingerprint(byte[] signature, java.lang.String alg)

		byte[]	result	= null;
		
		try
		{
			final MessageDigest md = MessageDigest.getInstance( alg );
			
			result	= md.digest( signature );
		}
		catch ( NoSuchAlgorithmException e )
		{
			result	= signature;
			e.printStackTrace();
		}
		
		return( result );
	
public static java.lang.Stringstringify(java.security.cert.X509Certificate cert)
Static variant when direct call will suffice.

		final StringBuffer	buf	= new StringBuffer();
		final String		NL	= "\n";
		
		buf.append( "Issuer: " + cert.getIssuerDN().getName() + NL);
		buf.append( "Issued to: " + cert.getSubjectDN().getName()  + NL);
		buf.append( "Version: " + cert.getVersion()  + NL);
		buf.append( "Not valid before: " + cert.getNotBefore()  + NL);
		buf.append( "Not valid after: " + cert.getNotAfter()  + NL);
		buf.append( "Serial number: " + cert.getSerialNumber()  + NL);	
		buf.append( "Signature algorithm: " + cert.getSigAlgName()  + NL);	
		buf.append( "Signature algorithm OID: " + cert.getSigAlgOID()  + NL);
		
		buf.append( "Signature fingerprint (MD5): " );
		byte[]	fingerprint	= getFingerprint( cert.getSignature(), "MD5" );
		buf.append( StringUtil.toHexString( fingerprint, ":" ) + NL );
		
		buf.append( "Signature fingerprint (SHA1): " );
		fingerprint	= getFingerprint( cert.getSignature(), "SHA1" );
		buf.append( StringUtil.toHexString( fingerprint, ":" )  + NL );
		
		return( buf.toString() );
	
public java.lang.Stringstringify(java.lang.Object object)

		return( stringify( (X509Certificate)object ) );