×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    62

    Question 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.

  2. #2
    Super Contributor
    Join Date
    Nov 2007
    Location
    Sertaozinho/Brazil
    Posts
    768

    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) :

    http://www.bouncycastle.org/latest_releases.html

    Marcelo

  3. #3
    Registered User
    Join Date
    Feb 2011
    Posts
    62

    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

  4. #4
    Super Contributor
    Join Date
    Nov 2007
    Location
    Sertaozinho/Brazil
    Posts
    768

    Re: SHA-256 hashing function in Java ME/J2ME

    Excellent, Infms. Thanks for posting the code snippet. Certainly it will help other people here.

Similar Threads

  1. reliable hashing algorithm?
    By mikecotic in forum Mobile Java General
    Replies: 2
    Last Post: 2008-11-12, 00:47
  2. Callng Java function from Symbian c++ app
    By shweta_912 in forum Mobile Java General
    Replies: 1
    Last Post: 2007-12-06, 04:38
  3. Symbian C++ and java function
    By pietro.versari in forum Symbian
    Replies: 4
    Last Post: 2007-03-06, 13:59
  4. If a function/class deprecated in java, what should i do?
    By mibuyt in forum Mobile Java General
    Replies: 2
    Last Post: 2003-09-29, 11:36
  5. C/DUI java function?
    By sgreid101 in forum Mobile Java General
    Replies: 0
    Last Post: 2003-08-18, 13:49

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×