List of usage examples for java.security NoSuchAlgorithmException printStackTrace
public void printStackTrace()
From source file:Main.java
public static String toMd5(String input) { String output = input;/*from w w w . j a va2s. c om*/ 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 getStringMD5(String key) { MessageDigest md5 = null;/* w ww.j a va2s .com*/ try { md5 = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } md5.update(key.getBytes()); //important: use Base64.URL_SAFE flag to avoid "+" and "/" return new String(Base64.encode(md5.digest(), Base64.URL_SAFE)); }
From source file:Main.java
private static byte[] encryptAlgorithm(byte[] data, String algorithm) { try {//from ww w .j a v a2 s . co m MessageDigest md = MessageDigest.getInstance(algorithm); md.update(data); return md.digest(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return new byte[0]; }
From source file:Main.java
private static byte[] hashTemplate(final byte[] data, final String algorithm) { if (data == null || data.length <= 0) return null; try {// ww w .ja v a 2 s. c o m MessageDigest md = MessageDigest.getInstance(algorithm); md.update(data); return md.digest(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); return null; } }
From source file:Main.java
public static KeyPair generateRSAKeyPair(int keyLength) { try {/*from ww w .j a va2 s. c o m*/ KeyPairGenerator kpg = KeyPairGenerator.getInstance(RSA); kpg.initialize(keyLength); return kpg.genKeyPair(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); return null; } }
From source file:Main.java
public static byte[] SHA1(String text) { if (null == text) { return null; }// w ww . j a va 2 s.c o m try { MessageDigest messageDigest = MessageDigest.getInstance("SHA1"); messageDigest.update(text.getBytes()); return messageDigest.digest(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); return null; } }
From source file:Main.java
private static byte[] hashTemplate(byte[] data, String algorithm) { if (data == null || data.length <= 0) return null; try {//from www . ja v a2 s . c o m MessageDigest md = MessageDigest.getInstance(algorithm); md.update(data); return md.digest(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); return null; } }
From source file:Main.java
public static String sha1(String s) { if (mSha1Digest == null) { try {//from w w w . j a v a 2s . c o m mSha1Digest = MessageDigest.getInstance("SHA-1"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } } byte[] data = mSha1Digest.digest(s.getBytes()); return String.format("%0" + (data.length * 2) + "X", new BigInteger(1, data)); }
From source file:Main.java
private static byte[] getHash(String password) { MessageDigest digest = null;// ww w . j a v a2 s . c o m try { digest = MessageDigest.getInstance("SHA-256"); } catch (NoSuchAlgorithmException e1) { e1.printStackTrace(); } if (digest != null) { digest.reset(); return digest.digest(password.getBytes()); } else { return null; } }
From source file:Main.java
public static String hash(String pass) { MessageDigest md = null;//from w ww.ja v a 2 s . co m try { md = MessageDigest.getInstance("SHA-256"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } md.update(pass.getBytes()); byte byteData[] = md.digest(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < byteData.length; i++) { sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1)); } return sb.toString(); }