SHA-256 hashing function in Java ME/J2ME
Hello everyone,
I'm writing an app which needs to find the SHA-256 hash of a URL keyed with a unique value – i.e. hmac('sha256', '27/3', '9EWVFmHpHN6n2YKW9QtvUqX3xbsFQUBovlrFddqnF7fpcSDA2q'). What would be the best way to do this in Java ME/J2ME? Is it even possible?
Many thanks in advance.
Re: SHA-256 hashing function in Java ME/J2ME
Infms
I haven´t tried yet but it seem that Bouncy Castle has the solution (see the (the lightweight API) :
[url]http://www.bouncycastle.org/latest_releases.html[/url]
Marcelo
Re: SHA-256 hashing function in Java ME/J2ME
Thanks Marcelo, the Bouncy Castle library works great! For those interested, the solution is as follows:
[CODE]Digest digest = new SHA256Digest();
HMac hmac = new HMac(digest);
hmac.init(new KeyParameter(appKeyHere));
hmac.update(requestURI, 0, lenOfReqURI);
byte[] resBuf = new byte[digest.getDigestSize()];
hmac.doFinal(resbuf, 0);
String resStr = new String(Hex.encode(resBuf)); // Contains final usable value[/CODE]
Re: SHA-256 hashing function in Java ME/J2ME
Excellent, Infms. Thanks for posting the code snippet. Certainly it will help other people here.