List of usage examples for java.security MessageDigest digest
public byte[] digest()
From source file:com.agiletec.plugins.jpuserreg.aps.system.services.userreg.util.ShaEncoder.java
public static String encodePassword(String password) throws NoSuchAlgorithmException { if (password != null) { MessageDigest digest = MessageDigest.getInstance("SHA"); digest.update(password.getBytes()); byte bytes[] = digest.digest(); StringBuffer buffer = new StringBuffer(); for (int i = 0; i < bytes.length; i++) { int b = bytes[i] & 0xff; if (b < 16) { buffer.append("0"); }// w ww . j a v a2 s . c o m buffer.append(Integer.toHexString(b)); } password = buffer.toString(); } return password; }
From source file:com.cisco.oss.foundation.directory.utils.ObfuscatUtil.java
/** * Compute the the hash value for the String. * * @param passwd//from w w w . j a va 2 s . c om * the password String * @return * the Hash digest byte. * @throws NoSuchAlgorithmException * the NoSuchAlgorithmException. */ public static byte[] computeHash(String passwd) throws NoSuchAlgorithmException { java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA-1"); md.reset(); md.update(passwd.getBytes()); return md.digest(); }
From source file:com.honnix.yaacs.util.MD5.java
/** * Get MD5 sum of the input data./* w w w . j av a2s . c o m*/ * * @param data * input data used to generate MD5 sum * @return MD5 sum of the input data, or null if no MD5 algorithm could be * found */ public static String getMD5Sum(String data) { String encodedData = null; try { MessageDigest messageDigest = MessageDigest.getInstance("MD5"); messageDigest.update(data.getBytes("US-ASCII"), 0, data.length()); encodedData = new BigInteger(1, messageDigest.digest()).toString(16); } catch (NoSuchAlgorithmException e) { StringBuilder sb = new StringBuilder("No MD5 algorithm.").append(" Could not apply validation check."); LOG.error(sb.toString(), e); } catch (UnsupportedEncodingException e) { LOG.error("This should not happen anyway.", e); } return encodedData; }
From source file:c3.ops.priam.utils.SystemUtils.java
public static byte[] md5(byte[] buf) { try {// w w w.j av a 2 s . c o m MessageDigest mdigest = MessageDigest.getInstance("MD5"); mdigest.update(buf, 0, buf.length); return mdigest.digest(); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.licc.common.util.Digests.java
public static String md5(String str) { try {/*from w w w . ja v a 2 s .co m*/ MessageDigest e = MessageDigest.getInstance("MD5"); e.update(str.getBytes()); byte[] b = e.digest(); StringBuffer buf = new StringBuffer(""); for (int offset = 0; offset < b.length; ++offset) { int i = b[offset]; if (i < 0) { i += 256; } if (i < 16) { buf.append("0"); } buf.append(Integer.toHexString(i)); } str = buf.toString(); } catch (Exception var6) { var6.printStackTrace(); } return str; }
From source file:com.corngo.base.support.utils.security.Digests.java
public final static String md5(String s) { char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; try {/* w w w . j a va2 s. c o m*/ byte[] btInput = s.getBytes(); MessageDigest mdInst = MessageDigest.getInstance("MD5"); mdInst.update(btInput); byte[] md = mdInst.digest(); int j = md.length; char str[] = new char[j * 2]; int k = 0; 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); } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:Main.java
public static String MD5(String text) { StringBuffer buffer;//from ww w . j a v a2s. c o m MessageDigest digest; byte[] data; int i, n; buffer = new StringBuffer(); try { digest = MessageDigest.getInstance("MD5"); digest.update(text.getBytes()); data = digest.digest(); for (i = 0, n = data.length; i < n; ++i) { buffer.append(Integer.toHexString(0xff & data[i])); } } catch (Exception e) { } return buffer.toString(); }
From source file:Main.java
public static String encode(String code) { MessageDigest md; try {// w ww . jav a 2 s . com md = MessageDigest.getInstance("MD5"); } catch (Exception e) { throw new RuntimeException(e); } md.update(code.getBytes()); byte[] buffer = md.digest(); StringBuffer hexString = new StringBuffer(2 * buffer.length); for (int i = 0; i < buffer.length; i++) { appendHexPair(buffer[i], hexString); } return hexString.toString(); }
From source file:cn.ucloud.sdk.utils.EncoderUtils.java
private static String encode(String algorithm, String str) { String result = null;// w w w . j a v a 2s . co m if (str == null) { return result; } try { MessageDigest messageDigest = MessageDigest.getInstance(algorithm); messageDigest.update(str.getBytes("UTF-8")); result = getFormattedText(messageDigest.digest()); } catch (Exception e) { LogUtils.exception(logger, e); } return result; }
From source file:com.ikanow.infinit.e.api.authentication.PasswordEncryption.java
/** * Encrypt the password//from www.java 2 s . c o m * @throws NoSuchAlgorithmException * @throws UnsupportedEncodingException */ public static String encrypt(String password) throws NoSuchAlgorithmException, UnsupportedEncodingException { MessageDigest md = MessageDigest.getInstance("SHA-256"); md.update(password.getBytes("UTF-8")); return Base64.encodeBase64String(md.digest()); }