List of utility methods to do Hash Calculate
char[] | getHashChars(byte[] bytes) get Hash Chars byte[] hash = getHash(bytes); char chars[] = new char[32]; for (int i = 0; i < chars.length; i = i + 2) { byte b = hash[i / 2]; chars[i] = HEX_CHARS[(b >>> 0x4) & 0xf]; chars[i + 1] = HEX_CHARS[b & 0xf]; return chars; ... |
String | getHashedPassword(String plainPassword) get Hashed Password String result = ""; MessageDigest md = null; try { md = MessageDigest.getInstance("SHA-256"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); md.update(plainPassword.getBytes()); ... |
String | getHashFromString(String str) Generates a sha-256 hash from a string Taken from http://stackoverflow.com/questions/415953/generate-md5-hash-in-java try { java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA-256"); byte[] array = md.digest(str.getBytes("UTF-8")); StringBuilder sb = new StringBuilder(); for (byte anArray : array) { sb.append(Integer.toHexString((anArray & 0xFF) | 0x100).substring(1, 3)); return sb.toString(); ... |
MessageDigest | getHashInstance(final String alg) get Hash Instance MessageDigest hash; try { hash = MessageDigest.getInstance(alg); } catch (NoSuchAlgorithmException ex) { throw new RuntimeException("As if " + alg + " isn't going to be implemented, bloody Java tossers"); return hash; |
byte[] | getHashKey(String input) get Hash Key byte[] bytesOfMessage = null, digestMessage = null; ByteBuffer buffer = ByteBuffer.allocate(16); if (input == null) { buffer.putInt(0, 0); return buffer.array(); try { bytesOfMessage = input.getBytes("UTF-8"); ... |
String | getHashMD5(File file) Generates MD5 hash for a given file. MessageDigest md; try { md = MessageDigest.getInstance("MD5"); FileInputStream fis = new FileInputStream(file); byte[] dataBytes = new byte[1024]; int nread = 0; while ((nread = fis.read(dataBytes)) != -1) { md.update(dataBytes, 0, nread); ... |
String | getHashMD5(String arg) get Hash MD return generateMD5Hash(arg);
|
String | getHashMD5(String str) Calls getHash(str, "MD5") try { return getHash(str, "MD5"); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); |
String | getHashMD5(String text) Calculates the MD5 hash of the string. byte[] bytes = text.getBytes(StandardCharsets.ISO_8859_1); return getHashMD5(bytes); |
String | getHashMDFive(String str) get Hash MD Five try { byte[] strBytes = str.getBytes("UTF-8"); MessageDigest md = MessageDigest.getInstance("MD5"); byte[] hashByte = md.digest(strBytes); StringBuilder sb = new StringBuilder(); for (byte aHashByte : hashByte) { sb.append(Integer.toString((aHashByte & 0xff) + 0x100, 16).substring(1)); return sb.toString(); } catch (UnsupportedEncodingException | NoSuchAlgorithmException e) { throw new RuntimeException(e); |