List of usage examples for java.security MessageDigest digest
public byte[] digest(byte[] input)
From source file:net.sf.jml.util.DigestUtils.java
public static byte[] md5(byte[] b) { try {// w ww . java2 s . c o m MessageDigest digest = MessageDigest.getInstance("MD5"); return digest.digest(b); } catch (NoSuchAlgorithmException e) { log.error(e, e); return null; } }
From source file:com.aast.encrypt.EncryptManager.java
private static byte[] getKeyFromString(String keyStr) throws UnsupportedEncodingException, NoSuchAlgorithmException { byte[] key = keyStr.getBytes("UTF-8"); MessageDigest sha = MessageDigest.getInstance("SHA-1"); key = sha.digest(key); key = Arrays.copyOf(key, 16); // use only first 128 bit return key;/*from w w w . j a v a 2s . co m*/ }
From source file:com.agiletec.plugins.jpnewsletter.aps.system.services.newsletter.util.ShaEncoder.java
public static String encodeWord(String word, String salt) throws NoSuchAlgorithmException { String saltedPass = mergeWordAndSalt(word, salt, false); MessageDigest messageDigest = MessageDigest.getInstance("SHA"); byte[] digest = messageDigest.digest(saltedPass.getBytes()); return new String(Hex.encodeHex(digest)); }
From source file:com.myjeeva.spring.security.util.SpringExtensionsUtil.java
/** * generates the MD5 Hash value from given salt value * //from w w w.ja v a2s .c om * @param md5Salt - a {@link java.lang.String} object. * @return md5 hash value if success, <code>null</code> if exception/fails */ public static String getMD5(String md5Salt) { try { MessageDigest md = MessageDigest.getInstance(MD5); byte[] array = md.digest(md5Salt.getBytes(UTF8)); StringBuffer sb = new StringBuffer(); for (int i = 0; i < array.length; ++i) { sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1, 3)); } return sb.toString(); } catch (java.security.NoSuchAlgorithmException e) { LOG.error(e.getMessage()); } catch (UnsupportedEncodingException e) { LOG.error(e.getMessage()); } return null; }
From source file:net.sf.jml.util.DigestUtils.java
public static byte[] sha1(byte[] b) { try {/*from www . j a v a2s. c om*/ MessageDigest digest = MessageDigest.getInstance("SHA-1"); return digest.digest(b); } catch (NoSuchAlgorithmException e) { log.error(e, e); return null; } }
From source file:com.bitbreeds.webrtc.signaling.CertUtil.java
/** * @return sha-256 string based on cert in keystore */// w ww . jav a 2s. c o m public static String getCertFingerPrint(String storePath, String alias, String pass) { try { Certificate cert = DTLSUtils.loadCert(storePath, alias, pass); byte[] der = cert.getCertificateAt(0).getEncoded(); MessageDigest md = MessageDigest.getInstance("SHA-256"); byte[] dat = md.digest(der); String fingerprint = createFingerprintString(dat); logger.info("Local cert signature is {} ", fingerprint); return fingerprint; } catch (Exception e) { logger.error("Failed to create cert fingerprint from {}", storePath, e); throw new IllegalStateException("Loading certificate failed"); } }
From source file:com.kumbaya.dht.Keys.java
public static KUID of(String key) { try {/*ww w. j av a 2 s .c om*/ MessageDigest md = MessageDigest.getInstance("SHA1"); KUID result = KUID.createWithBytes(md.digest(key.getBytes("UTF-8"))); md.reset(); return result; } catch (UnsupportedEncodingException e) { logger.warn("failed to encode key: " + key, e); return null; } catch (NoSuchAlgorithmException e) { logger.warn("failed to encode key: " + key, e); return null; } }
From source file:Main.java
/** * returns a hash SHA-1 of the given byte array * * @param data the data to be hashed//from w w w . j ava2 s. c o m * @return byte[] the hash of the data */ public static byte[] hash(String algorithm, byte[] data) { try { MessageDigest digest = MessageDigest.getInstance(algorithm); return digest.digest(data); } catch (NoSuchAlgorithmException e) { return null; } }
From source file:com.apexxs.neonblack.utilities.MD5Utilities.java
public static String getMD5Hash(String s) { String md5Hash = StringUtils.EMPTY; try {//from ww w .j a va2 s . c o m MessageDigest md = MessageDigest.getInstance("MD5"); md.reset(); byte[] bytes = md.digest(s.getBytes("UTF-8")); md5Hash = String.format("%032x", new BigInteger(1, bytes)); } catch (Exception ex) { logger.error("Error generating MD5 hash from " + s + "\n" + ex.getMessage()); } return md5Hash; }
From source file:com.linkedin.databus2.schemas.utils.Utils.java
public static byte[] md5(byte[] bytes) { try {// w w w . j a v a2 s .com MessageDigest digest = MessageDigest.getInstance("md5"); return digest.digest(bytes); } catch (NoSuchAlgorithmException e) { throw new IllegalStateException("This can't happen.", e); } }