Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Verifying a Digital Signature using message digest

843811Sep 10 2003 — edited Sep 10 2003
Hi, i am new to java.
I have a Digitally signed document, i wanna verify this signed document against the original one.
i got the idea from this link:
http://help.sap.com/saphelp_45b/helpdata/en/8d/517619da7d11d1a5ab0000e835363f/content.htm

i signed a pdf doc with my SmartCard. the third party signing tool passed me the PKCS7 digital signature and i stored it in database. the problem arose when i retrieved this digital signature from DB and verified against the original doc using the message digest method. the base64 result strings are always not equal.

I am sure about this:
-the retrieved digital signature was GOOD.
-the original doc was GOOD.
but why i can't get the same 2 message digests? can somebody please help?

below is part of my code:
..
..
while (rsetDs.next()) 
{
	InputStream DSName2 = rsetDs.getBinaryStream(1);
	ByteArrayOutputStream byteStream = new ByteArrayOutputStream();

	byte[] myByte = Base64.decode(byteStream.toString());
	ByteArrayInputStream newStream = new ByteArrayInputStream(myByte);


	CertificateFactory cf = CertificateFactory.getInstance("X.509");
	Collection c = cf.generateCertificates(newStream2);
	Iterator i = c.iterator();

	while (i.hasNext()) 
	{
		Certificate cert = (Certificate)i.next();
		X509Certificate cert1 = (X509Certificate)cert;
	
		try
		{
			java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5");

			/*=============DB MD (BEGIN)==================*/

			byte [] pubkeyByte = cert1.getPublicKey().getEncoded();

			md.update(myByte);
			md.update(pubkeyByte);
			byte[] raw = md.digest();

			String db_md = Base64.encode(raw);

			/*============DB MD (end)============*/

			/*=============PDF MD (BEGIN)==================*/
		
			DataInputStream m_disFile = new DataInputStream(new FileInputStream("C:\\" + "original_doc.pdf"));
			int m_iNum = m_disFile.available();
			byte[] msgBytes = new byte[m_iNum];
			m_iNum = m_disFile.read(msgBytes, 0, m_iNum);

			md.update(msgBytes);
			byte[] digestMd = md.digest();
			md.reset();

			String pdf_md = Base64.encode(digestMd);

			/*=============PDF MD (END)==================*/

		}
	}
}
..
..
thanks in advance.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 8 2003
Added on Sep 10 2003
1 comment
604 views