List of usage examples for java.security MessageDigest digest
public byte[] digest()
From source file:Main.java
public static String hashImgUrl(String imgUrl) throws NoSuchAlgorithmException { String imgKey = null;//from www.ja v a2 s . co m MessageDigest m = MessageDigest.getInstance("MD5"); m.reset(); m.update(imgUrl.getBytes()); byte[] digest = m.digest(); BigInteger bigInt = new BigInteger(1, digest); imgKey = bigInt.toString(16); while (imgKey.length() < 32) imgKey = "0" + imgKey; return imgKey; }
From source file:Main.java
public static String makeSHA1HashBase64(byte[] bytes) { try {/* w w w .jav a 2 s. com*/ MessageDigest md = MessageDigest.getInstance("SHA-1"); md.update(bytes, 0, bytes.length); byte[] sha1hash = md.digest(); return Base64.encodeToString(sha1hash, Base64.URL_SAFE | Base64.NO_PADDING | Base64.NO_WRAP); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } }
From source file:Main.java
/** * Computes the SHA1 Hash of given UTF-8 data. * * @param message/*from w w w . j a va2 s . co m*/ * @return * @throws UnsupportedEncodingException * @throws NoSuchAlgorithmException */ public static String SHA1(String message) throws UnsupportedEncodingException, NoSuchAlgorithmException { byte[] data = message.getBytes("UTF-8"); MessageDigest md = MessageDigest.getInstance("SHA1"); md.update(data, 0, data.length); byte[] digest = md.digest(); return bytesToHex(digest); }
From source file:Main.java
public static byte[] SHA1(String text) { if (null == text) { return null; }//from ww w .jav a 2 s.c o m try { MessageDigest messageDigest = MessageDigest.getInstance("SHA1"); messageDigest.update(text.getBytes()); return messageDigest.digest(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); return null; } }
From source file:Main.java
public static String encryptMD5(String password) { try {/*from ww w . ja v a 2 s. c o m*/ MessageDigest md = MessageDigest.getInstance("MD5"); md.update(password.getBytes()); byte byteData[] = md.digest(); StringBuffer hexString = new StringBuffer(); for (int i = 0; i < byteData.length; i++) { String hex = Integer.toHexString(0xff & byteData[i]); if (hex.length() == 1) hexString.append('0'); hexString.append(hex); } return hexString.toString(); } catch (Exception e) { e.printStackTrace(); } return ""; }
From source file:Main.java
public static String sha1(String s) { try {/*from ww w.ja v a2s .com*/ MessageDigest digest = MessageDigest.getInstance("SHA-1"); digest.update(s.getBytes()); byte messageDigest[] = digest.digest(); StringBuffer hexString = new StringBuffer(); for (int i = 0; i < messageDigest.length; i++) { hexString.append(Integer.toHexString((0xFF & messageDigest[i]) | 0x100).substring(1)); } return hexString.toString(); } catch (NoSuchAlgorithmException e) { return ""; } }
From source file:Main.java
public static String getMd5(String source) { try {/*from w ww. j av a 2 s . c om*/ MessageDigest md5 = MessageDigest.getInstance("MD5"); md5.update(source.getBytes()); BigInteger bi = new BigInteger(1, md5.digest()); return String.format("%032x", bi); } catch (Exception e) { return ""; } }
From source file:cn.zhuqi.mavenssh.ext.util.Coder.java
/** * MD5/*w w w. j av a 2 s .c o m*/ * * @param data * @return * @throws Exception */ public static byte[] encryptMD5(byte[] data) throws Exception { MessageDigest md5 = MessageDigest.getInstance(KEY_MD5); md5.update(data); return md5.digest(); }
From source file:cn.zhuqi.mavenssh.ext.util.Coder.java
/** * SHA//from w w w. ja va2 s. co m * * @param data * @return * @throws Exception */ public static byte[] encryptSHA(byte[] data) throws Exception { MessageDigest sha = MessageDigest.getInstance(KEY_SHA); sha.update(data); return sha.digest(); }
From source file:Main.java
public static String getStringMD5(String str) { String value = null;//from w w w .j a v a2 s. c om try { MessageDigest md5 = MessageDigest.getInstance("MD5"); md5.update(str.getBytes()); BigInteger bi = new BigInteger(1, md5.digest()); value = bi.toString(16).toUpperCase(); } catch (Exception e) { e.printStackTrace(); } return value; }