List of utility methods to do Checksum Calculate
boolean | checksum(String nmea) checksum int len = nmea.length(); if (len < 3) return false; try { String checksumString = nmea.substring(len - 2, len); int target = Integer.valueOf(checksumString, 16); int chk = computeChecksum(nmea); if (chk == target) ... |
int | checksum_icmpv6(byte pkt[]) checksuicmpv return checksum_icmpv6(pkt, 0);
|
String | checksumBytesToString(byte[] digestBytes) Converts a message digest byte array into a String based on the hex values appearing in the array. StringBuffer hexString = new StringBuffer(); for (int i = 0; i < digestBytes.length; i++) { String hex = Integer.toHexString(0xff & digestBytes[i]); if (hex.length() == 1) { hexString.append('0'); hexString.append(hex); return hexString.toString(); |
long | checksumFile(File file) checksum File return checksum(new FileInputStream(file)); |
int | checksumLength(int algorithmCode, int dataLength) checksum Length if (algorithmCode == NO_CHECKSUM) { return 0; } else { return (int) Math.ceil((double) dataLength / CHECK_CHUNK_SIZE) * 8; |
String | createChecksum(File file, String shaAlgo) create Checksum try { InputStream fis = new FileInputStream(file); byte[] buffer = new byte[1024]; MessageDigest complete = MessageDigest.getInstance(shaAlgo); int numRead; do { numRead = fis.read(buffer); if (numRead > 0) { ... |
String | generateChecksum(InputStream is) generate Checksum return generateChecksum(is, DEFAULT_ALGORITHM);
|
String | generateChecksum(String path, String flavor) Creates a checksum for a file by first reading in its byte and passing those bytes through a formula that allows each chunk of bytes to be read as an integer and then made into a String final byte[] digest = makeChecksum(path, flavor); String output = ""; for (int i = 0; i < digest.length; i++) { int current = (digest[i] & 0xff) + 0x100; output += Integer.toString(current, 16).substring(1); return output; |
String | generateChecksum(String pType, String pInFile) Generates a checksum for a file if (!new File(pInFile).exists()) throw new IOException("File not found: " + pInFile); MessageDigest md; try { md = MessageDigest.getInstance(pType.toUpperCase()); } catch (NoSuchAlgorithmException e) { return null; FileInputStream input; try { input = new FileInputStream(pInFile); byte[] readBuffer = new byte[BUFSIZE]; int bytesRead = 0; while (input.available() > 0) { bytesRead = input.read(readBuffer); md.update(readBuffer, 0, bytesRead); input.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); String hash = ""; for (byte b : md.digest()) hash += String.format("%02x", b); return hash; |
String | generateCheckSum(String string) This method generates a checksum from a passed string try { MessageDigest md = MessageDigest.getInstance("MD5"); md.update(string.getBytes()); byte byteData[] = md.digest(); StringBuilder hexString = new StringBuilder(); for (byte aByteData : byteData) { String hex = Integer.toHexString(0xff & aByteData); if (hex.length() == 1) ... |