List of usage examples for java.security NoSuchAlgorithmException printStackTrace
public void printStackTrace()
From source file:edu.cwru.apo.Auth.java
public static Hex md5(String in) { MessageDigest digest;/*from w ww.j a va 2 s.co m*/ try { digest = MessageDigest.getInstance("MD5"); digest.reset(); digest.update(in.getBytes()); byte messageDigest[] = digest.digest(); return new Hex(messageDigest); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return null; }
From source file:com.gmu.uav.RadioSecurity.java
public static String computeSHA256(String password) { MessageDigest messagDigest = null; String saltedPassword = null; SecureRandom random = new SecureRandom(); byte[] salt = new byte[SALT_BYTES]; random.nextBytes(salt);/*from w w w . ja v a2 s .com*/ saltedPassword = salt + password; try { messagDigest = MessageDigest.getInstance("SHA-256"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } messagDigest.update(saltedPassword.getBytes()); byte finalHash[] = messagDigest.digest(); return HASH_ITERATIONS + ":" + toHex(salt) + ":" + toHex(finalHash); }
From source file:database.DBAccountManager.java
private static String hashPassword(String password) { String digest;/* w w w.j a v a2 s. c o m*/ try { MessageDigest md = MessageDigest.getInstance("md5"); md.reset(); byte[] bytes = md.digest(password.getBytes()); digest = new BigInteger(1, bytes).toString(16); } catch (NoSuchAlgorithmException nsae) { nsae.printStackTrace(); digest = null; } return digest; }
From source file:Main.java
public static String getMD5EncryptedString(String encTarget) { MessageDigest mdEnc = null;// w w w. j a v a2s . c o m try { mdEnc = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { System.out.println("Exception while encrypting to md5"); e.printStackTrace(); } // Encryption algorithm mdEnc.update(encTarget.getBytes(), 0, encTarget.length()); String md5 = new BigInteger(1, mdEnc.digest()).toString(16); while (md5.length() < 32) { md5 = "0" + md5; } return md5; }
From source file:com.zen.androidhtmleditor.util.TextUtil.java
public static String MD5(String str, String encoding) { MessageDigest messageDigest = null; try {/*w w w . j a v a2 s . com*/ messageDigest = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } messageDigest.reset(); try { messageDigest.update(str.getBytes(encoding)); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } byte[] byteArray = messageDigest.digest(); StringBuffer md5StrBuff = new StringBuffer(); for (int i = 0; i < byteArray.length; i++) { if (Integer.toHexString(0xFF & byteArray[i]).length() == 1) md5StrBuff.append("0").append(Integer.toHexString(0xFF & byteArray[i])); else md5StrBuff.append(Integer.toHexString(0xFF & byteArray[i])); } return md5StrBuff.toString(); }
From source file:org.runway.utils.TextUtils.java
/** * Generates MD5 for the text passed//from w ww . j av a2s. c o m * @param text * @return */ public static String genMD5(String text) { MessageDigest m; try { m = MessageDigest.getInstance("MD5"); m.update(text.getBytes(), 0, text.length()); return new BigInteger(1, m.digest()).toString(16); } catch (NoSuchAlgorithmException e) {// return same text if there was // an error e.printStackTrace(); return text; } }
From source file:com.cloud.utils.ssh.SSHKeysHelper.java
public static String getPublicKeyFingerprint(String publicKey) { String key[] = publicKey.split(" "); if (key.length < 2) { throw new RuntimeException("Incorrect public key is passed in"); }//from w w w . j a v a 2 s. c o m byte[] keyBytes = Base64.decodeBase64(key[1]); MessageDigest md5 = null; try { md5 = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } String sumString = toHexString(md5.digest(keyBytes)); String rString = ""; for (int i = 2; i <= sumString.length(); i += 2) { rString += sumString.substring(i - 2, i); if (i != sumString.length()) rString += ":"; } return rString; }
From source file:com.subgraph.vega.internal.http.requests.AbstractHttpClientFactory.java
protected static SchemeRegistry createSchemeRegistry() { final SchemeRegistry sr = new SchemeRegistry(); sr.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); SSLContext ctx;/*from w ww . j a v a2s. com*/ try { ctx = SSLContext.getInstance("TLS"); X509TrustManager tm = new X509TrustManager() { public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException { } public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException { } public X509Certificate[] getAcceptedIssuers() { return null; } }; ctx.init(null, new X509TrustManager[] { tm }, null); SSLSocketFactory ssf = new SSLSocketFactory(ctx, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); sr.register(new Scheme("https", 443, ssf)); } catch (NoSuchAlgorithmException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (KeyManagementException e) { // TODO Auto-generated catch block e.printStackTrace(); } return sr; }
From source file:cl.niclabs.tscrypto.common.messages.EncryptedData.java
private static SecretKeySpec generateAESKey() { SecretKeySpec skeySpec = null; try {/*ww w. j a v a 2 s . c om*/ KeyGenerator keyGen = KeyGenerator.getInstance("AES"); keyGen.init(KEYSIZE_AES); // Generate the secret key specs. SecretKey secretKey = keyGen.generateKey(); skeySpec = new SecretKeySpec(secretKey.getEncoded(), "AES"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return skeySpec; }
From source file:com.moki.touch.util.UrlUtil.java
/** * This method is used to create a filename for cached content * @param url the url of the content to be cached * @return an MD5 hashed string/*from w w w .ja va2 s .c om*/ */ public static String hashUrl(String url) { try { // Create MD5 Hash MessageDigest digest = java.security.MessageDigest.getInstance("MD5"); digest.update(url.getBytes()); byte messageDigest[] = digest.digest(); // Create Hex String StringBuffer hexString = new StringBuffer(); for (int i = 0; i < messageDigest.length; i++) { String h = Integer.toHexString(0xFF & messageDigest[i]); while (h.length() < 2) h = "0" + h; hexString.append(h); } return hexString.toString(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return ""; }