List of usage examples for java.security MessageDigest reset
public void reset()
From source file:lucee.commons.digest.Hash.java
public static String hash(byte[] data, String algorithm, char[] encoding) throws NoSuchAlgorithmException { MessageDigest md = MessageDigest.getInstance(algorithm); md.reset(); md.update(data);/*from w ww. j av a 2 s .co m*/ return new String(enc(md.digest(), encoding)); // no charset needed because all characters are below us-ascii (hex) }
From source file:org.adempiere.webui.util.BrowserToken.java
private static String getPasswordHash(MSession session, MUser user) throws UnsupportedEncodingException, NoSuchAlgorithmException { MessageDigest digest = MessageDigest.getInstance("SHA-512"); Base64 encoder = new Base64(); digest.reset(); if (session.getWebSession() != null) digest.update(session.getWebSession().getBytes("UTF-8")); String password = null;/* w ww .j a v a 2s . c om*/ if (MSystem.isZKRememberPasswordAllowed()) password = user.getPassword(); else password = new String(""); byte[] input = digest.digest(password.getBytes("UTF-8")); String hash = new String(encoder.encode(input), "UTF-8"); hash = URLEncoder.encode(hash, "UTF-8"); return hash; }
From source file:lucee.commons.digest.Hash.java
public static String hash(String str, String nonce, String algorithm, char[] encoding) throws NoSuchAlgorithmException { MessageDigest md = MessageDigest.getInstance(algorithm); md.reset(); md.update(toBytes(str, CharsetUtil.UTF8)); md.update(DEL);/*from www . j a v a2 s. c o m*/ md.update(toBytes(nonce, CharsetUtil.UTF8)); return new String(enc(md.digest(), encoding)); // no charset needed because all characters are below us-ascii (hex) }
From source file:org.faster.util.Encrypts.java
/** * ?/*from www . jav a 2s. co m*/ * * @param algorithm ?? * @param plainText * @param salt ? * @return ? */ public static final String encrypt(String algorithm, String plainText, String salt) { MessageDigest md; try { md = MessageDigest.getInstance(algorithm); } catch (Exception e) { throw Exceptions.unchecked(e); } md.reset(); if (salt != null) { md.update(salt.getBytes()); } byte[] unencodedText = plainText.getBytes(); md.update(unencodedText); byte[] encodedText = md.digest(); return Base64.encodeBase64URLSafeString(encodedText); }
From source file:Main.java
private static byte[] getHash(String password) { MessageDigest digest = null; try {//from w w w . ja v a2 s.co m digest = MessageDigest.getInstance("SHA-256"); } catch (NoSuchAlgorithmException e1) { e1.printStackTrace(); } if (digest != null) { digest.reset(); return digest.digest(password.getBytes()); } else { return null; } }
From source file:com.linkedin.databus.client.registration.RegistrationIdGenerator.java
/** * Generate a hash out of the String id/*from w w w.j a va 2 s . co m*/ * * @param id * @return */ private static String generateByteHash(String id) { try { final MessageDigest messageDigest = MessageDigest.getInstance("MD5"); messageDigest.reset(); messageDigest.update(id.getBytes(Charset.forName("UTF8"))); final byte[] resultsByte = messageDigest.digest(); String hash = new String(Hex.encodeHex(resultsByte)); final int length = 8; if (hash.length() > length) hash = hash.substring(0, length); return hash; } catch (NoSuchAlgorithmException nse) { LOG.error("Unexpected error : Got NoSuchAlgorithm exception for MD5"); return ""; } }
From source file:com.algodefu.yeti.md5.MD5HashGenerator.java
public static String generateKeyByString(String string) { MessageDigest m = null; try {/* w ww . j av a2 s .c om*/ m = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } m.reset(); m.update(string.getBytes()); byte[] digest = m.digest(); BigInteger bigInt = new BigInteger(1, digest); String hashtext = bigInt.toString(16); while (hashtext.length() < 32) { hashtext = "0" + hashtext; } return hashtext; }
From source file:com.algodefu.yeti.md5.MD5HashGenerator.java
public static String generateKeyByObject(Object object) { MessageDigest m = null; try {/*w w w.j ava 2 s . c o m*/ m = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } m.reset(); //m.update(objectToByteArray(object)); m.update(SerializationUtils.serialize((Serializable) object)); byte[] digest = m.digest(); BigInteger bigInt = new BigInteger(1, digest); String hashtext = bigInt.toString(16); while (hashtext.length() < 32) { hashtext = "0" + hashtext; } return hashtext; }
From source file:Main.java
public static String md5(String str) { MessageDigest algorithm = null; try {//from ww w .j a v a 2s . c o m algorithm = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } if (algorithm != null) { algorithm.reset(); algorithm.update(str.getBytes()); byte[] bytes = algorithm.digest(); StringBuilder hexString = new StringBuilder(); for (byte b : bytes) { hexString.append(Integer.toHexString(0xFF & b)); } return hexString.toString(); } return ""; }
From source file:org.shredzone.cilla.web.comment.CommentThreadServiceImpl.java
/** * Computes a mail hash that can be used at Gravatar. * * @param mail/* w w w . j a v a 2s. c o m*/ * mail address * @return md5 hash */ private static String computeMailHash(String mail) { try { MessageDigest md5 = MessageDigest.getInstance("MD5"); md5.reset(); md5.update(mail.trim().toLowerCase().getBytes("UTF-8")); StringBuilder digest = new StringBuilder(); for (byte b : md5.digest()) { digest.append(String.format("%02x", b & 0xFF)); } return digest.toString(); } catch (NoSuchAlgorithmException | UnsupportedEncodingException ex) { // we expect no exception, since MD5 and UTF-8 are standards throw new InternalError(ex.getMessage()); } }