Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MessageDigest md = MessageDigest.getInstance("MD5");
- InputStream is = new FileInputStream("file.txt");
- try {
- is = new DigestInputStream(is, md);
- // read stream to EOF as normal...
- }
- finally {
- is.close();
- }
- byte[] digest = md.digest();
- FileInputStream fis = new FileInputStream( new File("foo" ) );
- String md5 = org.apache.commons.codec.digest.DigestUtils.md5Hex( fis );
- try {
- String s = "TEST STRING";
- MessageDigest md5 = MessageDigest.getInstance("MD5");
- md5.update(s.getBytes(),0,s.length());
- String signature = new BigInteger(1,md5.digest()).toString(16);
- System.out.println("Signature: "+signature);
- } catch (final NoSuchAlgorithmException e) {
- e.printStackTrace();
- }
- File myfile = new File("myfile.txt");
- long checksum = Files.getChecksum(myfile , new java.util.zip.CRC32());
- File myfile = new File("myfile.txt");
- byte[] digest = Files.getDigest(myfile , MessageDigest.getInstance("SHA-256"));
- public static String MD5Hash(String toHash) throws RuntimeException {
- try{
- return String.format("%032x", // produces lower case 32 char wide hexa left-padded with 0
- new BigInteger(1, // handles large POSITIVE numbers
- MessageDigest.getInstance("MD5").digest(toHash.getBytes())));
- }
- catch (NoSuchAlgorithmException e) {
- // do whatever seems relevant
- }
- }
- ...
- String signature = new BigInteger(1,md5.digest()).toString(16);
- ...
- String hash = MD5.asHex(MD5.getHash(new File(filename)));
- <checksum file="${jarFile}" todir="${toDir}"/>
Add Comment
Please, Sign In to add comment