Java ME/J2ME中的SHA-256哈希函数 [英] SHA-256 hashing function in Java ME/J2ME

查看:165
本文介绍了Java ME/J2ME中的SHA-256哈希函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在诺基亚开发者论坛上发布了这个问题,请耐心等待.

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

我正在编写一个应用,该应用需要查找以唯一值(即hmac('sha256', '27/3', '9EWVFmHpHN6n2YKW9QtvUqX3xbsFQUBovlrFddqnF7fpcSDA2q'))键入的URL的SHA-256哈希.用Java ME/J2ME做到这一点的最佳方法是什么?

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?

我发现许多使用Mac类的示例,但是Java ME/J2ME不支持此示例.

I've found many examples using the Mac class but this isn't supported in Java ME/J2ME.

谢谢.

推荐答案

我设法使工作正常进行,解决方案如下:

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

这篇关于Java ME/J2ME中的SHA-256哈希函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆