List of usage examples for java.security MessageDigest update
public final void update(ByteBuffer input)
From source file:Main.java
private static byte[] encryptAlgorithm(byte[] data, String algorithm) { try {// w ww . j av a 2 s . c o m MessageDigest md = MessageDigest.getInstance(algorithm); md.update(data); return md.digest(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return new byte[0]; }
From source file:Main.java
private static byte[] hashTemplate(final byte[] data, final String algorithm) { if (data == null || data.length <= 0) return null; try {/* w w w.j a v a 2s . c o m*/ MessageDigest md = MessageDigest.getInstance(algorithm); md.update(data); return md.digest(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); return null; } }
From source file:net.cheesecan.cheeselobby.session.MD5Base64Hash.java
public static String encrypt(String str) throws NoSuchAlgorithmException { MessageDigest md = MessageDigest.getInstance("MD5"); md.update(str.getBytes()); byte[] enc = md.digest(); return new String(new Base64().encode(enc)); }
From source file:Main.java
public static byte[] md5(byte[] bytes) { try {//from w w w . j ava 2 s.c o m MessageDigest messageDigest = MessageDigest.getInstance("MD5"); messageDigest.update(bytes); return messageDigest.digest(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return null; }
From source file:Main.java
private static byte[] hashTemplate(byte[] data, String algorithm) { if (data == null || data.length <= 0) return null; try {// w ww. j a v a2s . co m MessageDigest md = MessageDigest.getInstance(algorithm); md.update(data); return md.digest(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); return null; } }
From source file:Main.java
public static String cryptoStr2MD5(String str) { try {/*from ww w . j av a 2s . c om*/ MessageDigest md = MessageDigest.getInstance("MD5"); md.update(str.getBytes()); byte[] bytes = md.digest(); return byte2Hex(bytes); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); return null; } }
From source file:de.kaojo.security.util.SecureHashingAlgorithmHelper.java
public static String hashSHA256(String input) throws NoSuchAlgorithmException { MessageDigest md = MessageDigest.getInstance(ALGORITHM); md.update(input.getBytes()); byte[] digest = md.digest(); byte[] encode = Base64.encodeBase64(digest); return new String(encode); }
From source file:Main.java
public static String sha1(String s) { try {/*from w w w.j a v a2 s . 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 md5String(String val) { if (val == null) return null; byte[] resBytes; try {/*from www . j av a 2s . com*/ MessageDigest md = MessageDigest.getInstance("MD5"); md.update(val.getBytes("UTF-8")); resBytes = md.digest(); return hexString(resBytes); } catch (Exception e) { return null; } }
From source file:Main.java
public final static String MD5(String s) throws Exception { char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; byte[] strTemp = s.getBytes(); MessageDigest mdTemp = MessageDigest.getInstance("MD5"); mdTemp.update(strTemp); byte[] md = mdTemp.digest(); int j = md.length; char str[] = new char[j * 2]; int k = 0;// w ww . jav a 2s . c o m for (int i = 0; i < j; i++) { byte byte0 = md[i]; str[k++] = hexDigits[byte0 >>> 4 & 0xf]; str[k++] = hexDigits[byte0 & 0xf]; } return new String(str); }