List of usage examples for java.security MessageDigest digest
public byte[] digest()
From source file:com.sfalma.trace.Sfalma.java
public static String MD5(String data) throws Exception { MessageDigest m = MessageDigest.getInstance("MD5"); m.update(data.getBytes(), 0, data.length()); return new BigInteger(1, m.digest()).toString(16); }
From source file:Main.java
/** * Generates SHA256 hash of the password which is used as key * * @param password used to generated key * @return SHA256 of the password/*from w ww . j a va 2 s. c o m*/ */ private static SecretKeySpec generateKey(final String password) throws NoSuchAlgorithmException, UnsupportedEncodingException { final MessageDigest digest = MessageDigest.getInstance(HASH_ALGORITHM); byte[] bytes = password.getBytes("UTF-8"); digest.update(bytes, 0, bytes.length); byte[] key = digest.digest(); log("SHA-256 key ", key); return new SecretKeySpec(key, "AES"); }
From source file:edu.cwru.apo.Auth.java
public static Hex md5(String in) { MessageDigest digest; try {//from ww w . java 2 s .c o m digest = MessageDigest.getInstance("MD5"); digest.reset(); digest.update(in.getBytes()); byte messageDigest[] = digest.digest(); return new Hex(messageDigest); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return null; }
From source file:com.pfarrell.crypto.HmacUtil.java
/** * calculate the sha of the argument, return hex encoded value * @param message to hash/* w w w .ja va 2s .co m*/ * @return hexified result */ public static String sha(byte[] message) { Preconditions.checkNotNull(message); byte[] gas = null; try { MessageDigest digest = MessageDigest.getInstance("SHA-256"); digest.update(message); gas = digest.digest(); } catch (Exception e) { System.out.println("WebUtils.sha256 - caught exception: " + e.toString()); } return hexify(gas); }
From source file:io.wcm.caravan.pipeline.cache.couchbase.impl.CouchbaseCacheAdapter.java
private static String calculateHash(String message) { try {//from w w w. java 2 s . co m MessageDigest digest = MessageDigest.getInstance("SHA-1"); digest.update(message.getBytes(CharEncoding.UTF_8)); byte[] digestBytes = digest.digest(); return javax.xml.bind.DatatypeConverter.printHexBinary(digestBytes).toLowerCase(); } catch (NoSuchAlgorithmException | UnsupportedEncodingException ex) { throw new RuntimeException("Failed to create sha1 Hash from " + message, ex); } }
From source file:Main.java
public static String md5One(String s) { MessageDigest md = null; try {// w w w. j a va 2 s . c o m md = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e.getMessage()); } md.update(s.getBytes()); return byteArrayToHexString(md.digest()); }
From source file:de.innovationgate.utils.UIDGenerator.java
/** * Generates an MD5 hash from the given string * @param hashString//from w ww . j a v a2s .c om */ public static String generateMD5Hash(String hashString) { MessageDigest md5; try { md5 = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { return null; } md5.update(hashString.getBytes()); byte[] array = md5.digest(); StringBuffer sb = new StringBuffer(); for (int j = 0; j < array.length; ++j) { int b = array[j] & 0xFF; if (b < 0x10) sb.append('0'); sb.append(Integer.toHexString(b)); } return sb.toString(); }
From source file:com.liferay.mobile.android.util.PortraitUtil.java
protected static void appendToken(StringBuilder sb, String uuid) { if (Validator.isNull(uuid)) { return;/* w w w . j a v a 2 s .c o m*/ } try { MessageDigest digest = MessageDigest.getInstance("SHA-1"); digest.update(uuid.getBytes()); byte[] bytes = digest.digest(); String token = null; try { token = Base64.encodeToString(bytes, Base64.NO_WRAP); } catch (RuntimeException re) { if ("Stub!".equals(re.getMessage())) { token = org.apache.commons.codec.binary.Base64.encodeBase64String(bytes); } } if (token != null) { sb.append("&img_id_token="); sb.append(URLEncoder.encode(token, "UTF8")); } } catch (Exception e) { Log.e(_CLASS_NAME, "Couldn't generate portrait image token", e); } }