I\'m looking for a way of getting an SHA-1 checksum with a Java byte array as the message.
Should I use a third party tool or is there something built in to the JVM
I Just used this to compute the hash sum inside of a dex file and compare it with the value which is saved in the dex file.
i know this code hasnt very good style but its more PoC and only needed for some research which isnt time critical. may someone can use it!
class CheckDex{
public boolean checkSHA1(File f) throws IOException, NoSuchAlgorithmException{
RandomAccessFile raf = new RandomAccessFile(f, "r");
byte[] sig = new byte[20];
raf.seek(0xC);
for(int i = 0; i < 20; i++){
sig[i] = (byte) raf.readUnsignedByte();
}
MessageDigest md = MessageDigest.getInstance("SHA-1");
byte[] code = new byte[(int) (raf.length()-32)];
for(int i = 0; i < code.length; i++){
code[i] = (byte) raf.readUnsignedByte();
}
byte[] comsig = md.digest(code);
raf.close();
return Arrays.equals(sig,comsig);
}
}