SHA-256 hashing function in Java ME/J2ME

前端 未结 2 1444
春和景丽
春和景丽 2021-01-17 01:52

I\'ve posted this question on the Nokia Developer forums so please bear with me.

I\'m writing an app which needs to find the SHA-256 hash of a URL keyed with a uniqu

相关标签:
2条回答
  • 2021-01-17 02:13

    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.

    0 讨论(0)
  • 2021-01-17 02:15

    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
    
    0 讨论(0)
提交回复
热议问题