How to generate a Aho-Corasick hash
I have recently started developing an open source anti virus software, although the hashes are generated with the Aho-Corasick algorithm.
I would love to know how to generate Aho-Corasick hashes from executables, as I have found barely any information on the internet regardin开发者_C百科g this
In Java:
private static String readFile(String path) throws IOException {
FileInputStream stream = new FileInputStream(new File(path));
try {
FileChannel fc = stream.getChannel();
MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
/* Instead of using default, pass in a decoder. */
return Charset.defaultCharset().decode(bb).toString();
}
finally {
stream.close();
}
}
Then you can use, following to get MD5 hash
byte[] bytesOfMessage = readFile("filepath").getBytes("UTF-8");
MessageDigest md = MessageDigest.getInstance("MD5");
String thedigest = Arrays.toString[md.digest(bytesOfMessage)];
精彩评论