Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Security / August 2006

Tip: Looking for answers? Try searching our database.

Generating the same SecretKey for XML Signature

Thread view: 
Michael Wilde - 06 Aug 2006 13:24 GMT
Hello,

I'm trying to use Java's HMAC to sign an XML document, and I'm having
mixed success. On the one hand, I know how to compute a correct
HMAC-value out of some shared-secret, but on the other hand I do not
know how to use this in the context of XML signature.

The example I see everywhere is similar to the following:

   KeyGenerator keyGen = KeyGenerator.getInstance("HmacSHA1");
   SecretKey key = keyGen.generateKey();

Unfortunately, generateKey() always produces a new key, which makes it
a bit hard to authenticate. After looking through the web and through
this newsgroup, I can't seem to find someone with the same problem as
I. Is there some way to generate the same SecretKey each time, using an
array of bytes, so that someone can authenticate what I send?

I need something like this:

   SecretKeySpec keyspec = new SecretKeySpec(sharedSecret, "HmacSHA1");
   KeyGenerator keyGenerator = KeyGenerator.getInstance("HmacSHA1");
   SecretKey secretKey = keyGenerator.generateKey();

and with that secretKey I would like to use:

   XMLSignature sig = new XMLSignature(document, null,
               XMLSignature.ALGO_ID_MAC_HMAC_SHA1,
               Canonicalizer.ALGO_ID_C14N_EXCL_OMIT_COMMENTS);
   sig.sign(secretKey);

Can anyone help me here?

TIA,
Michael.

--
[1] http://www.w3.org/TR/xkms2/#XKMS_2_0_Section_C_1
Mr. Skeptic - 08 Aug 2006 02:51 GMT
> Unfortunately, generateKey() always produces a new key, which makes it
> a bit hard to authenticate. After looking through the web and through
[quoted text clipped - 22 lines]
> --
> [1] http://www.w3.org/TR/xkms2/#XKMS_2_0_Section_C_1

If you look carefully at the lineage of SecretKeySpec, you'll see that
it implements SecretKey. Thus you should be able to do:
          sig.sign(keyspec)


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.