How to get Thumbprint of a cert?

Hi,

I use 1.4.2 jdk. I need to have secure communications with Directory servers - meaning work with SSLs. I want to get the value of thumbprint of an X509Certificate retrieved from a directory server. How can I do that? I realized there is no direct method call on X509Certificate class.

Searching online blessed me with a link related to this:

http://archives.java.sun.com/cgi-bin/wa?A2=ind0407&L=java-security&F=&S=&P=4456

I used the following method to convert bytes into Hexadecimal strings:

******************

static String toHexString(byte[] buf, int off, int len)

{

StringBuffer str = new StringBuffer();

for (int i = 0; i < len; i++)

{

String HEX = "0123456789abcdef";

str.append(HEX.charAt(buf[i+off] >>> 4 & 0x0F));

str.append(HEX.charAt(buf[i+off] & 0x0F));

}

return str.toString();

}

*********************************

The resultant string is a valid String, but it does not look like a Thumbprint. it looks some thing like "acedbc024h759jkdhuu2885973jh8dgjj5", as oppsed to a typical Thumprint looking like "2f f7 67 uy 92 g4 r4 57 5h j7 h2 8f".

I would appreciate the help.

[1247 byte] By [peddipa] at [2007-10-1 7:20:03]
# 1

Hi Peddip,

You have to put spaces in between System.out.println(" "); Also check the get Instance if the Thumbprint is not matching.

MessageDigest md = MessageDigest.getInstance("MD5");

or

MessageDigest md = MessageDigest.getInstance("SHA");

Hope this will help..

Cheers !

Sanjeev

Sanjeev_Sria at 2007-7-9 18:29:31 > top of Java-index,Security,Cryptography...