Skip to main content

java MessageDigest

If you use MessageDigest in java to encrypt string, you wont get hash like other language does.
So you need to convert the result so that you can compare the hash result with other output that produce by diff language.
Found the function on the java net forum

private static String baToHexString(byte byteValues[]) {
byte singleChar = 0;

if (byteValues == null || byteValues.length <= 0) return null;
String entries[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" };
StringBuffer out = new StringBuffer(byteValues.length * 2);
for (int i = 0; i < byteValues.length; i++) {
singleChar = (byte) (byteValues[i] & 0xF0);
singleChar = (byte) (singleChar >>> 4);
// shift the bits down
singleChar = (byte) (singleChar & 0x0F);
out.append(entries[(int) singleChar]);
singleChar = (byte) (byteValues[i] & 0x0F);
out.append(entries[(int) singleChar]);
}

String rslt = new String(out);

return rslt;

}

Comments

Popular posts from this blog

django realtime currency rate

Its been a really long time since I post something here For some dumb reason, I forgot my blogger login/password :hammer: Anyway, since I'm now heavily work with django stuff Here are some django related projects that hopefully can benefit anyone who need it * django-currency_rate, simple django app that can give you realtime currency rate base on http://themoneyconverter.com . Owh its even can calculate the rate with templatetag :) https://github.com/avenpace/django-exchange_rate

python-oauth2 hack

When you are using python-oauth2 from simplegeo on your Google App Engine instance, you'll get some exception that cause by "ImportError: No module named httplib2" Yes, apparently httplib2 are not supported by GAE and instead they oblige you to use google.appengine.api.urlfetch.fetch instead So I hack python-oauth2 to use google.appengine.api.urlfetch.fetch You can found my python-oauth2 fork on https://github.com/avenpace/python-oauth2

Another django cms base

Cooper-cms, a really simple cms built with django that probably suitable for company site. It has testimonial, team, content and blog (of course :) ) modules. I know its not fancy as django-cms but it will suit for some simple company site though https://bitbucket.org/avenpace/cooper-cms