Reputation: 107
I just want to encode a given string to HmacSHA256 according to a private key in java.anyone can provide a simple program....?
Upvotes: 1
Views: 3738
Reputation: 2089
SecureRandom sr = new SecureRandom();
byte[] keyBytes = new byte[20];
sr.nextBytes(keyBytes);
SecretKey key = new SecretKeySpec(keyBytes, "HmacSHA1");
Mac m = Mac.getInstance("HmacSHA1");
m.init(key);
m.update(inputData);
byte[] mac = m.doFinal();
Copied from 'http://oreilly.com/catalog/javacrypt/chapter/ch06.html', you'll find all other cryptographic information there.
Upvotes: 4