List of usage examples for java.security NoSuchAlgorithmException printStackTrace
public void printStackTrace()
From source file:Main.java
public static String hashkeyForDisk(String url) { try {// w ww. j a v a2 s . c om 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 cryptoStr2MD5(String str) { try {// www . ja va2s . co m MessageDigest md = MessageDigest.getInstance("MD5"); md.update(str.getBytes()); byte[] bytes = md.digest(); return byte2Hex(bytes); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); return null; } }
From source file:Main.java
public static String crypt(String senha) { try {// ww w . j av a 2 s. c o m MessageDigest digest = MessageDigest.getInstance("MD5"); digest.update(senha.getBytes()); byte messageDigest[] = digest.digest(); StringBuffer hexString = new StringBuffer(); for (int i = 0; i < messageDigest.length; i++) { hexString.append(Integer.toHexString(0xFF & messageDigest[i])); } return hexString.toString(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); return senha; } }
From source file:Main.java
public static String cryptoStr2SHA1(String str) { try {/*from ww w . j a va 2s . c om*/ MessageDigest md = MessageDigest.getInstance("SHA-1"); md.update(str.getBytes()); byte[] bytes = md.digest(); return byte2Hex(bytes); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); return null; } }
From source file:Main.java
public static String generateShortUuid() { UUID uuid = UUID.randomUUID(); MessageDigest md = null;//from w w w . j a v a 2 s. c o m try { md = MessageDigest.getInstance("SHA-256"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); return uuid.toString(); } md.update(uuid.toString().getBytes()); byte[] digest = md.digest(); return Base64.encodeToString(digest, Base64.URL_SAFE | Base64.NO_WRAP | Base64.NO_PADDING).substring(0, 20); }
From source file:Main.java
public static String md5(byte[] data) { try {//www . j a va 2 s . c o m MessageDigest messageDigest = MessageDigest.getInstance("MD5"); messageDigest.update(data); return bytesToHex(messageDigest.digest()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return ""; }
From source file:Main.java
public final static String md5(String value) { try {/* w w w.j a v a 2s .com*/ 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
/** * //w ww . j a v a2 s. co m * @param word * the string to be hashed * @return SHA1-hash of the word */ public static String hash(String word) { byte[] data = word.getBytes(); MessageDigest md = null; try { md = MessageDigest.getInstance("SHA-1"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } byte[] b = md.digest(data); String result = ""; for (int i = 0; i < b.length; i++) { result += Integer.toString((b[i] & 0xff) + 0x100, 16).substring(1); } return result; }
From source file:Main.java
public static Cipher createCipher(String algorithmProviderPadding, SecretKey sk, int mode) { try {// ww w.jav a2s . com Cipher ch = Cipher.getInstance(algorithmProviderPadding); ch.init(mode, sk); return ch; } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (NoSuchPaddingException e) { e.printStackTrace(); } catch (InvalidKeyException e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static String MD5Crypto(String str) { try {//w w w . ja va 2 s. c om // Create MD5 Hash MessageDigest digest = MessageDigest.getInstance("MD5"); digest.update(str.getBytes()); byte messageDigest[] = digest.digest(); return toHexString(messageDigest); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return ""; }