List of usage examples for java.security MessageDigest update
public void update(byte[] input, int offset, int len)
From source file:Main.java
public static String SHA1(String text) throws NoSuchAlgorithmException, UnsupportedEncodingException { MessageDigest md = MessageDigest.getInstance("SHA-1"); md.update(text.getBytes("iso-8859-1"), 0, text.length()); byte[] sha1hash = md.digest(); return convertToHex(sha1hash); }
From source file:Sha1.java
public static String sha1(String text) { try {/*from ww w. j a v a 2 s . c o m*/ MessageDigest md = MessageDigest.getInstance("SHA-1"); md.update(text.getBytes("iso-8859-1"), 0, text.length()); return convertToHex(md.digest()); } catch (Exception e) { throw new Exception(format("Problem hashing %s", text), e); } }
From source file:Main.java
public static String computeMD5(byte[] input) { try {/*from w w w. jav a 2 s. c om*/ MessageDigest md = MessageDigest.getInstance("MD5"); md.update(input, 0, input.length); byte[] md5bytes = md.digest(); StringBuffer hexString = new StringBuffer(); for (int i = 0; i < md5bytes.length; i++) { String hex = Integer.toHexString(0xff & md5bytes[i]); if (hex.length() == 1) hexString.append('0'); hexString.append(hex); } return hexString.toString(); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } }
From source file:Main.java
public static String computeMD5(byte[] input) { try {//w w w . jav a2 s . c om MessageDigest md = MessageDigest.getInstance("MD5"); md.update(input, TYPE_NOT_CONNECTED, input.length); byte[] md5bytes = md.digest(); StringBuffer hexString = new StringBuffer(); for (int i = TYPE_NOT_CONNECTED; i < md5bytes.length; i += TYPE_WIFI) { String hex = Integer.toHexString(md5bytes[i] & MotionEventCompat.ACTION_MASK); if (hex.length() == TYPE_WIFI) { hexString.append('0'); } hexString.append(hex); } return hexString.toString(); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } }
From source file:Main.java
public static byte[] computeSHA1(byte[] convertme, int offset, int len) { try {/*from w w w . ja v a 2 s. com*/ MessageDigest md = MessageDigest.getInstance("SHA-1"); md.update(convertme, offset, len); return md.digest(); } catch (Exception e) { e.printStackTrace(); } return new byte[20]; }
From source file:Main.java
public static String makeMD5Hash(byte[] bytes) { try {/*ww w. j av a2 s. co m*/ MessageDigest md = MessageDigest.getInstance("MD5"); md.update(bytes, 0, bytes.length); byte[] sha1hash = md.digest(); return convertToHex(sha1hash); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
From source file:D_common.E_ncript.java
public static String getMd5(String s) { try {/*from w ww . j av a 2 s . co m*/ MessageDigest m = MessageDigest.getInstance("MD5"); m.update(s.getBytes(), 0, s.length()); return new BigInteger(1, m.digest()).toString(16); } catch (Exception e) { e.printStackTrace(); return ""; } }
From source file:Main.java
public static String makeSHA1Hash(byte[] bytes) { try {/*from w ww. j a va 2 s. c om*/ MessageDigest md = MessageDigest.getInstance("SHA-1"); md.update(bytes, 0, bytes.length); byte[] sha1hash = md.digest(); return convertToHex(sha1hash); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
From source file:Main.java
public static String getMD5Hash(String s) throws NoSuchAlgorithmException { MessageDigest m = MessageDigest.getInstance("MD5"); byte[] data = s.getBytes(); m.update(data, 0, data.length); BigInteger i = new BigInteger(1, m.digest()); return String.format("%1$032X", i); }
From source file:Main.java
/*** * compute hash for text//from w w w .j av a2 s. c o m * * @param text * @return * @throws NoSuchAlgorithmException * @throws UnsupportedEncodingException */ public static String SHA1(String text) throws NoSuchAlgorithmException, UnsupportedEncodingException { MessageDigest md = MessageDigest.getInstance("SHA-1"); md.update(text.getBytes("iso-8859-1"), 0, text.length()); byte[] sha1hash = md.digest(); return convertToHex(sha1hash); }