class FileChecksumSHA256Service {

    public String createChecksum(String filepath){
		notNull(filepath, "filepath may not be null");
		MessageDigest md;
		String algorithm = "SHA-256";
		 try {
			md = MessageDigest.getInstance(algorithm);
		} catch (NoSuchAlgorithmException e) {
			throw new IllegalStateException("Algorithm not supported:"+algorithm);
		}
        // file hashing with DigestInputStream
        try (DigestInputStream dis = new DigestInputStream(new FileInputStream(filepath), md)) {
            while (dis.read() != -1) ; //empty loop to clear the data
            md = dis.getMessageDigest();
        }catch(IOException e) {
        	return null;
        }

        // bytes to hex
        StringBuilder result = new StringBuilder();
        for (byte b : md.digest()) {
            result.append(String.format("%02x", b));
        }
        return result.toString();

    }

}