SHA-256 hashing function in Java ME/J2ME

最后都变了- 提交于 2019-12-01 14:20:55

I managed to get things working, the solution is as follows:

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

BouncyCastle's latest J2ME compatible release (the lightweight API) contains among other things an SHA256 implementation - org.bouncycastle.crypto.digests.SHA256Digest - that should work for you.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!