JCE: generateing HmacSHA1

T

Timo Nentwig

Hi!

I'm not very familiar with all the hashing and encrypting stuff.

I used to generate the hash (or MAC or whatever) with a Windows util called
HashCalc (google :). I can enter the data to create the SHA1 from and I can
enter data for HMAC - and the latter is the problem. I didn' figure out how
this can be done with JCE.

Can somebody cast some light on the issue or is there a free alternative to
JCE?

Thanks
Timo
 
T

Timo Nentwig

Timo said:
I used to generate the hash (or MAC or whatever) with a Windows util
called HashCalc (google :). I can enter the data to create the SHA1 from
and I can enter data for HMAC - and the latter is the problem. I didn'
figure out how this can be done with JCE.

Ok, in other words:

I can archieve what I want using the implemention of freenet.crypt:

final byte[] msg = Hex.decodeHex( "010a".toCharArray() );
final byte[] hmac = Hex.decodeHex( "090f".toCharArray() );

final HMAC s = new HMAC( SHA1.getInstance() );
byte[] mv = s.mac( hmac, msg, 20 );

for ( int i = 0; i < mv.length; i++ )
System.out.print( byte2hex( mv ) );

How do I implement the same with JCE?
 
T

Timo Nentwig

Timo said:
How do I implement the same with JCE?

final byte[] msg = "foo".getBytes();
final byte[] key = "bar".getBytes();

final SecretKeySpec hmac = new SecretKeySpec( key, "HmacSHA1" );

final Mac mac = Mac.getInstance( hmac.getAlgorithm() );
mac.init( hmac );

final byte[] digest = mac.doFinal( msg );
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top