List of usage examples for java.security NoSuchAlgorithmException printStackTrace
public void printStackTrace()
From source file:jBittorrentAPI.utils.Utils.java
/** * Compute the SHA-1 hash of the bytes in the given buffer * @param hashMe ByteBuffer/*w ww . ja va 2 s . com*/ * @return byte[] */ public static byte[] hash(ByteBuffer hashMe) { try { MessageDigest md = MessageDigest.getInstance("SHA-1"); md.update(hashMe); return md.digest(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return null; }
From source file:jBittorrentAPI.utils.Utils.java
/** * Compute the SHA-1 hash of the given byte array * @param hashMe byte[]// w ww . jav a2 s . c om * @return byte[] */ public static byte[] hash(byte[] hashMe, String algorithm) { try { MessageDigest md = MessageDigest.getInstance(algorithm); return md.digest(hashMe); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); System.err.println(algorithm + " algorithm is not available..."); System.exit(2); } return null; }
From source file:net.dries007.coremod.Coremod.java
public static String getChecksum(File file) { try {/*ww w. ja v a2s. c om*/ final MessageDigest md = MessageDigest.getInstance("SHA1"); final FileInputStream fis = new FileInputStream(file); final byte[] dataBytes = new byte[1024]; int nread = 0; while ((nread = fis.read(dataBytes)) != -1) { md.update(dataBytes, 0, nread); } final byte[] mdbytes = md.digest(); // convert the byte to hex format final StringBuffer sb = new StringBuffer(""); for (int i = 0; i < mdbytes.length; i++) { sb.append(Integer.toString((mdbytes[i] & 0xff) + 0x100, 16).substring(1)); } fis.close(); return sb.toString(); } catch (final NoSuchAlgorithmException e) { e.printStackTrace(); } catch (final IOException e) { e.printStackTrace(); } return null; }
From source file:fr.sedona.volley.manager.HttpImageLoader.java
public static String md5(String s) { if (s == null) { return null; }// w w w . jav a 2 s . c o m try { byte messageDigest[] = MessageDigest.getInstance("MD5").digest(s.getBytes()); // Create Hex String BigInteger bi = new BigInteger(1, messageDigest); String result = bi.toString(16); if (result.length() % 2 != 0) result = (new StringBuilder("0")).append(result).toString(); return result; } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return ""; }
From source file:fr.sedona.volley.manager.HttpImageLoader.java
public static String md5(ByteArrayOutputStream s) { if (s == null) { return null; }/*from w w w. ja v a2s .com*/ try { byte messageDigest[] = MessageDigest.getInstance("MD5").digest(s.toByteArray()); // Create Hex String BigInteger bi = new BigInteger(1, messageDigest); String result = bi.toString(16); if (result.length() % 2 != 0) result = (new StringBuilder("0")).append(result).toString(); return result; } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return ""; }
From source file:com.aqnote.shared.cryptology.digest.SHA.java
public final static String sha3_224(byte[] src) { if (src == null) return ""; try {/*w w w . j a v a 2 s . c om*/ MessageDigest md = MessageDigest.getInstance("SHA3-224", JCE_PROVIDER); md.update(src); return new String(ByteUtil.toHexBytes(md.digest())); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (NoSuchProviderException e) { e.printStackTrace(); } return ""; }
From source file:com.aqnote.shared.cryptology.digest.SHA.java
public final static String sha3_256(byte[] src) { if (src == null) return ""; try {/* w ww.ja v a 2s .c o m*/ MessageDigest md = MessageDigest.getInstance("SHA3-256", JCE_PROVIDER); md.update(src); return new String(ByteUtil.toHexBytes(md.digest())); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (NoSuchProviderException e) { e.printStackTrace(); } return ""; }
From source file:com.aqnote.shared.cryptology.digest.SHA.java
public final static String sha3_384(byte[] src) { if (src == null) return ""; try {/*from www. j a va2 s . c o m*/ MessageDigest md = MessageDigest.getInstance("SHA3-384", JCE_PROVIDER); md.update(src); return new String(ByteUtil.toHexBytes(md.digest())); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (NoSuchProviderException e) { e.printStackTrace(); } return ""; }
From source file:com.aqnote.shared.cryptology.digest.SHA.java
public final static String sha3_512(byte[] src) { if (src == null) return ""; try {/* w ww . ja v a 2 s . c o m*/ MessageDigest md = MessageDigest.getInstance("SHA3-512", JCE_PROVIDER); md.update(src); return new String(ByteUtil.toHexBytes(md.digest())); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (NoSuchProviderException e) { e.printStackTrace(); } return ""; }
From source file:com.aqnote.shared.cryptology.digest.SHA.java
public final static String sha1(byte[] src) { if (src == null) return ""; try {/*from ww w .j a v a2s .c om*/ // MessageDigest md = MessageDigest.getInstance("SHA-1"); MessageDigest md = MessageDigest.getInstance(OID_SHA1, JCE_PROVIDER); md.update(src); return new String(ByteUtil.toHexBytes(md.digest())); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (NoSuchProviderException e) { e.printStackTrace(); } return ""; }