[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[iaik-jce] Subject Key Identifier Extension

I'm wondering if anyone has got a good way of generating
the Subject Key identifier Extension from the Subjects Public Key.

"The keyIdentifier is composed of a four bit type field with
the value 0100 followed by the least significant 60 bits of the
SHA-1 hash of the value of the BIT STRING subjectPublicKey."

According to the RFC (above)
I should be able to do like this.

	byte[] keyEncoded = publicKey.getEncoded();
	MessageDigest sha = null;
	try {
		sha = MessageDigest.getInstance("SHA");
	} catch (java.security.NoSuchAlgorithmException e)

	byte[] hash_value = sha.digest();

	keyBitString = new BIT_STRING(hash_value);
	String shaBinaryString = keyBitString.getBinaryString();
	shaBinaryString = shaBinaryString.substring(100,160);
	shaBinaryString = "0100" + shaBinaryString;

	SubjectKeyIdentifier subjectKey =
	BIT_STRING subjectKeyBITSTRING = new BIT_STRING(subjectKey.get());
	String subjectKeyString = subjectKeyBITSTRING.egtBinaryString();

After this code shouldn't shaBinaryString have the same value as
Am I doing something totaly wrong?

Thanks before hand

Regards Tobias Adamson
Mailinglist-archive at http://jcewww.iaik.at/mailarchive/iaik-jce/jcethreads.html

To unsubscribe send an email to listserv@iaik.at with the folowing content: UNSUBSCRIBE iaik-jce