List of usage examples for java.security MessageDigest update
public final void update(ByteBuffer input)
From source file:Main.java
public static String hashkeyForDisk(String url) { try {//from w w w. ja va 2s .c o m final MessageDigest digest = MessageDigest.getInstance("MD5"); digest.update(url.getBytes()); return bytesToHexString(digest.digest()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); return String.valueOf(url.hashCode()); } }
From source file:Main.java
public static String generateMD5Hash(String textToBeHashed) { try {//from w w w . j a v a2s .c o m MessageDigest messageDigest = MessageDigest.getInstance(MD5); messageDigest.update(textToBeHashed.getBytes()); byte[] messageDigestByte = messageDigest.digest(); StringBuffer MD5Hash = new StringBuffer(); String h; for (int i = 0; i < messageDigestByte.length; ++i) { h = Integer.toHexString((0xFF & messageDigestByte[i]) | 0x100).substring(1, 3); MD5Hash.append(h); } return MD5Hash.toString(); } catch (Exception e) { throw new RuntimeException("Couldn't generate MD5 hash for " + textToBeHashed); } }
From source file:Main.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 va 2 s . c o m byte[] strTemp = s.getBytes("UTF-8"); MessageDigest mdTemp = MessageDigest.getInstance("MD5"); mdTemp.update(strTemp); byte[] md = mdTemp.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) { return null; } }
From source file:Main.java
public static String hexSHA1(String value) { try {/*from w w w. j a v a 2 s . c o m*/ MessageDigest md = MessageDigest.getInstance("SHA-1"); md.update(value.getBytes("utf-8")); byte[] digest = md.digest(); return byteToHexString(digest); } catch (Exception ex) { throw new RuntimeException(ex); } }
From source file:Main.java
public static void printOutMyHashKey(Context context, String packageName) { try {//from www . j a v a2 s . c o m PackageInfo info = context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_SIGNATURES); for (Signature signature : info.signatures) { MessageDigest md = MessageDigest.getInstance("SHA"); md.update(signature.toByteArray()); Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT)); } } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } }
From source file:Main.java
public static String getMD5(String input) { String result = null;//from w w w .j a v a 2s .c o m try { MessageDigest md = MessageDigest.getInstance("MD5"); md.update(input.getBytes()); byte[] digest = md.digest(); StringBuffer sb = new StringBuffer(); for (byte b : digest) { sb.append(String.format("%02x", b & 0xff)); } result = sb.toString(); } catch (Exception ex) { ex.printStackTrace(); } finally { return result; } }
From source file:Main.java
public static String MD5(String s) { try {//from www. j a v a2 s . c om MessageDigest md = MessageDigest.getInstance("MD5"); md.update(s.getBytes()); byte b[] = md.digest(); int i; StringBuilder buf = new StringBuilder(""); for (int offset = 0; offset < b.length; offset++) { i = b[offset]; if (i < 0) i += 256; if (i < 16) buf.append("0"); buf.append(Integer.toHexString(i)); } return buf.toString(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return "null"; }
From source file:Main.java
public static String SHA1(String s) { try {//from w w w.j a v a2 s . c o m MessageDigest digest = MessageDigest.getInstance("SHA-1"); digest.update(s.getBytes()); byte messageDigest[] = digest.digest(); return toHexString(messageDigest); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return ""; }
From source file:Main.java
private static byte[] getKeyBytes(String mykey) { try {// w w w . j a va 2 s .co m MessageDigest digest = java.security.MessageDigest.getInstance("MD5"); digest.update(mykey.getBytes(Charset.forName("UTF-8"))); return digest.digest(); } catch (NoSuchAlgorithmException e) { Log.e(TAG, "Password creation exception: " + e.toString()); return errorbyte; } }
From source file:Main.java
public static String getHashKey(Context context) { // Add code to print out the key hash try {/*from w ww . ja v a 2 s . co m*/ PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES); for (Signature signature : info.signatures) { MessageDigest md = MessageDigest.getInstance("SHA"); md.update(signature.toByteArray()); return Base64.encodeToString(md.digest(), Base64.DEFAULT); } } catch (NameNotFoundException e) { } catch (NoSuchAlgorithmException e) { } return null; }