List of usage examples for java.security MessageDigest update
public final void update(ByteBuffer input)
From source file:com.adaptris.core.mail.attachment.MailContent.java
private static String calculateHash(byte[] b) { String result = null;/*from w w w . jav a2s . c o m*/ try { MessageDigest md = MessageDigest.getInstance("MD5"); md.update(b); byte[] hash = md.digest(); result = Conversion.byteArrayToBase64String(hash); } catch (Exception e) { ; } return result; }
From source file:Main.java
public static String getMessageDigest(byte[] paramArrayOfByte) { char[] arrayOfChar1 = { 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 97, 98, 99, 100, 101, 102 }; String str;// w w w .j av a2s . c o m try { MessageDigest localMessageDigest = MessageDigest.getInstance("MD5"); localMessageDigest.update(paramArrayOfByte); byte[] arrayOfByte = localMessageDigest.digest(); int i = arrayOfByte.length; char[] arrayOfChar2 = new char[i * 2]; int j = 0; int k = 0; while (true) { if (j >= i) { str = new String(arrayOfChar2); break; } int m = arrayOfByte[j]; int n = k + 1; arrayOfChar2[k] = arrayOfChar1[(0xF & m >>> 4)]; k = n + 1; arrayOfChar2[n] = arrayOfChar1[(m & 0xF)]; j++; } } catch (Exception localException) { str = null; } return str; }
From source file:br.com.bluesoft.pronto.service.Seguranca.java
public static String encrypt(final String x) { try {//from w w w .jav a2 s . c om final MessageDigest md = MessageDigest.getInstance("MD5"); md.update(x.getBytes()); final byte[] hashMd5 = md.digest(); final byte[] base64 = Base64.encodeBase64(hashMd5); return new String(base64); } catch (final Exception e) { return null; } }
From source file:Main.java
/** * md5// w w w. j a v a 2 s . c om * * @param str * @return */ public static String md5(String str) { try { MessageDigest messageDigest = MessageDigest.getInstance("MD5"); messageDigest.reset(); messageDigest.update(str.getBytes("UTF-8")); byte[] byteArray = messageDigest.digest(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < byteArray.length; i++) { if (Integer.toHexString(0xFF & byteArray[i]).length() == 1) { sb.append("0").append(Integer.toHexString(0xFF & byteArray[i])); } else { sb.append(Integer.toHexString(0xFF & byteArray[i])); } } return sb.toString(); } catch (Exception e) { e.printStackTrace(); } return str; }
From source file:Main.java
public static String get_device_id(Context ctx) { final TelephonyManager tm = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE); String tmDevice = ""; String tmSerial = null;//from www .j av a2 s . c o m String androidId = null; try { tmDevice = "" + tm.getDeviceId(); } catch (Exception ex) { } try { tmSerial = "" + tm.getSimSerialNumber(); } catch (Exception ex) { } try { androidId = "" + android.provider.Settings.Secure.getString(ctx.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID); } catch (Exception ex) { } try { UUID deviceUuid = new UUID(androidId.hashCode(), ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode()); String deviceId = deviceUuid.toString(); MessageDigest md = MessageDigest.getInstance("SHA-256"); md.update(deviceId.getBytes()); byte byteData[] = md.digest(); //convert the byte to hex format method 1 StringBuffer sb = new StringBuffer(); for (int i = 0; i < byteData.length; i++) { sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1)); } deviceId = sb.toString(); return deviceId; } catch (Exception ex) { } return "nodeviceid"; }
From source file:Main.java
public static String MD5(String paramString) { if (paramString == null) return null; try {//w w w. jav a 2 s .co m byte[] arrayOfByte1 = paramString.getBytes(); MessageDigest localMessageDigest = MessageDigest.getInstance("MD5"); localMessageDigest.reset(); localMessageDigest.update(arrayOfByte1); byte[] arrayOfByte2 = localMessageDigest.digest(); StringBuffer localStringBuffer = new StringBuffer(); for (int i = 0; i < arrayOfByte2.length; i++) { Object[] arrayOfObject = new Object[1]; arrayOfObject[0] = Byte.valueOf(arrayOfByte2[i]); localStringBuffer.append(String.format("%02X", arrayOfObject)); } String str = localStringBuffer.toString(); return str; } catch (Exception localException) { } return paramString.replaceAll("[^[a-z][A-Z][0-9][.][_]]", ""); }
From source file:com.aqnote.shared.cryptology.digest.SM.java
public final static String sm3(byte[] src) { if (src == null) return ""; try {/*w ww . j a va 2 s. co m*/ MessageDigest md = MessageDigest.getInstance(OID_SM3, JCE_PROVIDER); md.update(src); return new String(Hex.encode(md.digest())); } catch (NoSuchAlgorithmException | NoSuchProviderException e) { e.printStackTrace(); } return ""; }
From source file:Main.java
public static String md5(String input) { try {/*w w w. ja va 2 s.c o m*/ MessageDigest messageDigest = MessageDigest.getInstance("MD5"); messageDigest.update(input.getBytes()); byte[] resultByteArray = messageDigest.digest(); char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; char[] resultCharArray = new char[resultByteArray.length * 2]; int index = 0; for (byte b : resultByteArray) { resultCharArray[index++] = hexDigits[b >>> 4 & 0xf]; resultCharArray[index++] = hexDigits[b & 0xf]; } return new String(resultCharArray); } catch (NoSuchAlgorithmException e) { return null; } }
From source file:StringUtils.java
public static String hashString(String sPassword) { if (sPassword == null || sPassword.equals("")) { return "empty:"; } else {/* w ww . j a v a2s .co m*/ try { MessageDigest md = MessageDigest.getInstance("SHA-1"); md.update(sPassword.getBytes("UTF-8")); byte[] res = md.digest(); return "sha1:" + byte2hex(res); } catch (NoSuchAlgorithmException e) { return "plain:" + sPassword; } catch (UnsupportedEncodingException e) { return "plain:" + sPassword; } } }
From source file:de.hybris.platform.b2b.punchout.services.impl.AsymmetricManager.java
/** * Generates a hash using asymmetric encryption. * // w w w.j a v a 2 s . c o m * @param unsecureText * The text to be hashed. * @param salt * The salt used to defend against dictionary and rainbow table attacks. * @return The hash. */ public static String getHash(final String unsecureText, final String salt) { try { final MessageDigest digest = MessageDigest.getInstance(ALGORITHM); digest.update(unsecureText.getBytes(CHAR_SET)); digest.update(salt.getBytes(CHAR_SET)); final byte[] byteData = digest.digest(); //convert the byte to hex format method 1 final StringBuffer sb = new StringBuffer(); for (int i = 0; i < byteData.length; i++) { sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1)); } return sb.toString(); } catch (NoSuchAlgorithmException | UnsupportedEncodingException e) { // should never happen LOG.error("System was unable to generate the hash.", e); } return null; }