It’s just data

Base64 of SHA1 for J2ME

The motivation for this implementation was Java enabled cellphones with tight memory requirements.  Russell Beattie ported this code to Java, I then inlined everything that was called once to reduce the footprint.

J2SE implementations can use the builtin java.security classes.  demo


You can honestly take my name out of that code now - it has little to do with anything I contributed, really. Adding types to someone else's script and then giving it to you to clean up and make work does not equal a contribution. :-)

Nice job Sam! Now if I can just get the freakin app to work.

-Russ

Posted by Russ at

Sam Ruby: Base64 of SHA1 for J2ME

Sam Ruby: Base64 of SHA1 for J2ME...

Excerpt from Jonas Galvez (english/portuguese)'s Bookmarks at

I think there's a typo in the code

  result[i] = base64[(((words[word] & 0x03) << 4) |
  ((words[word+1] >> 28) & 0x1F)) & 0x3F];

should be:

  result[i] = base64[(((words[word] & 0x03) << 4) |
  ((words[word+1] >> 28) & 0x0F)) & 0x3F];

i.e the 0x1F constant should be 0x0F

Posted by John Wilson at

It is said that "Many Eyes Make All Bugs Shallow".

This indeed was in error.  Fixed.  Thanks!

In case anybody find this code handy, I've added an explicit BSD license to the source.

Posted by Sam Ruby at

Java enabled cellphones - help has arrived

Sam Ruby has come up with a little treat for Java enabled cell phone users that are plagued with limited memory....... [more]

Trackback from Lockergnome's Web Developers

at

Another typo... I'm pretty sure that's not JavaScript. ;)

Posted by Matt Chaput at

Matt: thanks!  Fixed.

Posted by Sam Ruby at

Sam Ruby: Base64 of SHA1 for J2ME

SHA 1 for J2ME...

Excerpt from del.icio.us/askdon2001 at

Does not work with binary files.
I found another solution. Go and see Bouncy Castle Java lightweight implementation.
[link]

Posted by anonymous at

Hi,

Many thanks for this implementation.
Would you be kind enough to help me get the hash as a byte array ?
Just as the MessageDigest.getInstance("SHA-1").digest();
would do in regular J2SE Java.

I’m not an expert in crypto and I cant figure out where to do that in your code.

I’ve been trying to convert the Base64 String you return to a byte[] but the result for a given string doesn’t match with the one given by MessageDigest ...

Any help greatly appreciated ! :)

Cheers,

Alex

Posted by Alex at

j2me SHA1 Fingerprint SSL Server Certificate

Hello all, Is there a way in j2me to “calculate” the SHA1 Fingerprint of a Server SSL Certificate that it is exchange during an HttpsConnection? i know that there is only custom implementations of sha1 algorithm in j2me like...

Excerpt from Main : Thread List - Java ME at

I found the problem in this part:
blks[i >> 2] |= x[i] << (24 - (i % 4) * 8);

To create the correct hash, we must correctly convert BYTE to INT:
blks[i >> 2] |= (x[i] & 0x0FF) << (24 - (i % 4) * 8);

Posted by Sten at

Add your comment