List of usage examples for java.math BigInteger BigInteger
private BigInteger(byte[] magnitude, int signum)
From source file:Main.java
public static String GetHash(byte[] data) { MessageDigest md;//from w w w. j av a 2 s .c om String hash = null; try { md = MessageDigest.getInstance("MD5"); hash = new BigInteger(1, md.digest(data)).toString(16); } catch (NoSuchAlgorithmException e) { Log.i("BMSUtil", "Hashing Error!"); e.printStackTrace(); } return hash; }
From source file:Main.java
public static String getMD5(String input) { try {// w w w . ja v a 2 s.com MessageDigest md = MessageDigest.getInstance("MD5"); byte[] messageDigest = md.digest(input.getBytes()); BigInteger number = new BigInteger(1, messageDigest); String hashtext = number.toString(16); // Now we need to zero pad it if you actually want the full 32 chars. while (hashtext.length() < 32) { hashtext = "0" + hashtext; } return hashtext; } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } }
From source file:Main.java
public final static String md5(String value) { try {/*from w w w .ja v a 2 s.co m*/ MessageDigest md = MessageDigest.getInstance("MD5"); byte[] messageDigest = md.digest(value.getBytes()); BigInteger number = new BigInteger(1, messageDigest); String md5 = number.toString(16); while (md5.length() < 32) { md5 = "0" + md5; } return md5; } catch (NoSuchAlgorithmException e) { e.printStackTrace(); return null; } }
From source file:Main.java
public static String toMd5(String input) { String output = input;/*from w w w . j a va 2 s . com*/ try { MessageDigest md5 = MessageDigest.getInstance("MD5"); md5.update(input.getBytes(), 0, input.length()); output = new BigInteger(1, md5.digest()).toString(16); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return output; }
From source file:Main.java
public static String hashImgUrl(String imgUrl) throws NoSuchAlgorithmException { String imgKey = null;//from ww w .j a v a 2 s . c o m MessageDigest m = MessageDigest.getInstance("MD5"); m.reset(); m.update(imgUrl.getBytes()); byte[] digest = m.digest(); BigInteger bigInt = new BigInteger(1, digest); imgKey = bigInt.toString(16); while (imgKey.length() < 32) imgKey = "0" + imgKey; return imgKey; }
From source file:Main.java
public static String md5(String senha) { String sen = ""; MessageDigest md = null;//from www . ja v a 2 s . co m try { md = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { Log.w("Problemas ao gerar MD5", e); } BigInteger hash = new BigInteger(1, md.digest(senha.getBytes())); sen = hash.toString(16); return sen; }
From source file:Main.java
public static String getMd5Digest(String pInput) { if (pInput == null) return ""; try {/*w w w. j av a 2 s . co m*/ MessageDigest lDigest = MessageDigest.getInstance("MD5"); lDigest.update(getBytes(pInput)); BigInteger lHashInt = new BigInteger(1, lDigest.digest()); return String.format("%1$032X", lHashInt); } catch (NoSuchAlgorithmException lException) { throw new RuntimeException(lException); } }
From source file:Main.java
public static String getMd5Digest(final String pInput) { if (pInput != null) { try {/*from ww w. j a v a2s .com*/ final MessageDigest lDigest = MessageDigest.getInstance("MD5"); lDigest.update(getBytes(pInput)); final BigInteger lHashInt = new BigInteger(1, lDigest.digest()); return String.format("%1$032X", lHashInt); } catch (final NoSuchAlgorithmException lException) { return pInput; } } return null; }
From source file:Main.java
public static String getSHA1Digest(final String pInput) { if (pInput != null) { try {/*from ww w . ja v a2s . c om*/ final MessageDigest lDigest = MessageDigest.getInstance("SHA1"); lDigest.update(getBytes(pInput)); final BigInteger lHashInt = new BigInteger(1, lDigest.digest()); return String.format("%1$032X", lHashInt); } catch (final NoSuchAlgorithmException lException) { return pInput; } } return null; }
From source file:Main.java
private static String encode(String str, String method) { MessageDigest md = null;//w ww .j av a 2 s .co m String dstr = null; try { md = MessageDigest.getInstance(method); md.update(str.getBytes()); dstr = new BigInteger(1, md.digest()).toString(16); int dstrCount = 32 - dstr.length(); for (int i = 0; i < dstrCount; i++) { dstr = "0" + dstr; } } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return dstr; }