md5 - MessageDigest.Digest, cannot catch the exception android -


i have trouble code, heres method bothering me.

public static byte[] createchecksum(byte[] b){     messagedigest md;     try {         md = messagedigest.getinstance("md5");         md.update(b);         byte[] checksum = md.digest();         return checksum;     } catch (nosuchalgorithmexception e) {          e.printstacktrace();     }     catch(exception e){         e.printstacktrace();     }     return null; } 

what happens statement md.digest() executed steps directly return null. dunno goes wrong, problem inside android?

edit: wanna note using java.security.messagedigest , not android.security.messagedigest

as can see there not exceptions digest method, reacts if there error inside function, send 186 bytes in array method.

i changed code bit, seems work, when use digest outside try catch, can't explain why, unless update change fixed it.

public static byte[] createchecksum(byte[] b){     messagedigest md = null;     try {         md = messagedigest.getinstance("md5");       } catch (nosuchalgorithmexception e) {          e.printstacktrace();     }     md.update(b,0,b.length);     byte[] checksum = md.digest();     return checksum; } 

Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -