List of usage examples for java.security NoSuchAlgorithmException printStackTrace
public void printStackTrace()
From source file:Main.java
public static String getApkSignatureMD5String(Signature signature) { MessageDigest md;/* ww w.j av a 2 s .c o m*/ try { md = MessageDigest.getInstance("MD5"); md.update(signature.toByteArray()); byte[] digest = md.digest(); return toHexString(digest); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return ""; }
From source file:com.algodefu.yeti.md5.MD5HashGenerator.java
public static String generateKeyByString(String string) { MessageDigest m = null;//from ww w.j av a2 s. c o m try { m = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } m.reset(); m.update(string.getBytes()); byte[] digest = m.digest(); BigInteger bigInt = new BigInteger(1, digest); String hashtext = bigInt.toString(16); while (hashtext.length() < 32) { hashtext = "0" + hashtext; } return hashtext; }
From source file:Main.java
@SuppressWarnings("finally") public static String getMD5(String str) { StringBuffer strBuf = new StringBuffer(); try {/*from w w w . ja va2 s.co m*/ MessageDigest md = MessageDigest.getInstance("MD5"); md.update(str.getBytes()); byte[] result16 = md.digest(); char[] digit = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; for (int i = 0; i < result16.length; i++) { char[] c = new char[2]; c[0] = digit[result16[i] >>> 4 & 0x0f]; c[1] = digit[result16[i] & 0x0f]; strBuf.append(c); } } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } finally { return strBuf.toString(); } }
From source file:com.algodefu.yeti.md5.MD5HashGenerator.java
public static String generateKeyByObject(Object object) { MessageDigest m = null;/*from w ww . j ava 2 s . c om*/ try { m = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } m.reset(); //m.update(objectToByteArray(object)); m.update(SerializationUtils.serialize((Serializable) object)); byte[] digest = m.digest(); BigInteger bigInt = new BigInteger(1, digest); String hashtext = bigInt.toString(16); while (hashtext.length() < 32) { hashtext = "0" + hashtext; } return hashtext; }
From source file:Main.java
/** *Valid plugin md5/* w ww. j av a 2s .c o m*/ * @param path bundle archvie path * @param md5Sum target file md5 * @return if md5 matched,return true * ***/ public static boolean validFileMD5(String path, String md5Sum) { try { MessageDigest messageDigest = MessageDigest.getInstance("MD5"); File mFile = new File(path); if (mFile == null || !mFile.exists() || !mFile.isFile()) { return false; } FileInputStream in = new FileInputStream(mFile); FileChannel ch = in.getChannel(); MappedByteBuffer byteBuffer = ch.map(FileChannel.MapMode.READ_ONLY, 0, mFile.length()); messageDigest.update(byteBuffer); String digest = String.format("%032x", new BigInteger(1, messageDigest.digest())); return md5Sum.equals(digest.toString()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { } return false; }
From source file:Main.java
public static String getBytesMacEncrypt(byte[] bytes, SecretKey key) { String algorithm = key.getAlgorithm(); if (algorithm.equals(HmacMD5) || algorithm.equals(HmacSHA1) || algorithm.equals(HmacSHA256) || algorithm.equals(HmacSHA384) || algorithm.equals(HmacSHA512)) { Mac mac = null;//from w w w . ja va 2 s. c om try { mac = Mac.getInstance(algorithm); mac.init(key); return bytes2String(mac.doFinal(bytes)); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (InvalidKeyException e) { e.printStackTrace(); } } return null; }
From source file:Main.java
public static String md5s(String plainText) { String str = ""; try {/*from ww w. j av a 2 s.c om*/ MessageDigest md = MessageDigest.getInstance("MD5"); md.update(plainText.getBytes()); byte b[] = md.digest(); int i; StringBuffer buf = new StringBuffer(""); 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)); } str = buf.toString(); } catch (NoSuchAlgorithmException e) { // TODO Auto-generated catch block e.printStackTrace(); } return str; }
From source file:org.sunriseframework.util.Hash.java
public static String generateHash(byte[] input, String algorithm) { MessageDigest algo;/* w w w . j a v a 2 s . c o m*/ String passwordHash = null; try { algo = MessageDigest.getInstance(algorithm); //MD5, SHA-1 algo.reset(); algo.update(input); Base64 encoder = new Base64(); passwordHash = new String(encoder.encode(algo.digest())); } catch (NoSuchAlgorithmException e) { // TODO Auto-generated catch block e.printStackTrace(); } return passwordHash; }
From source file:Main.java
public static PublicKey getPublicKey(String n, String publicExponent) { KeySpec publicKeySpec = new RSAPublicKeySpec(new BigInteger(n, 16), new BigInteger(publicExponent, 16)); KeyFactory factory = null;/*from ww w.j av a 2s.c o m*/ PublicKey publicKey = null; try { factory = KeyFactory.getInstance(KEY_ALGORITHM); } catch (NoSuchAlgorithmException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } try { publicKey = factory.generatePublic(publicKeySpec); } catch (InvalidKeySpecException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } return publicKey; }
From source file:com.tydic.dbp.utils.ThreeDesUtils.java
public static String encryptMode(String Src) { try {//from w ww .j av a2s . c om // ? SecretKey deskey = new SecretKeySpec(keyBytes, Algorithm); // Cipher c1 = Cipher.getInstance(Algorithm); c1.init(Cipher.ENCRYPT_MODE, deskey); return Hex.encodeHexString(c1.doFinal(Src.getBytes())); } catch (java.security.NoSuchAlgorithmException e1) { e1.printStackTrace(); } catch (javax.crypto.NoSuchPaddingException e2) { e2.printStackTrace(); } catch (java.lang.Exception e3) { e3.printStackTrace(); } return null; }