List of usage examples for java.security NoSuchAlgorithmException printStackTrace
public void printStackTrace()
From source file:com.wootric.androidsdk.utils.SHAUtil.java
public static String buildUniqueLink(String accountToken, String endUserEmail, long date, String randomString) { String unixTimestamp = String.valueOf(date); String randomText = randomString; String text = accountToken + endUserEmail + unixTimestamp + randomText; MessageDigest mDigest = null; String uniqueLink = null;// w ww . ja v a2s . c o m try { mDigest = MessageDigest.getInstance("SHA-256"); byte[] result = mDigest.digest(text.getBytes()); uniqueLink = new String(Hex.encodeHex(result)); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return uniqueLink; }
From source file:Main.java
public static String getSignatureString(Signature sig, String type) { byte[] hexBytes = sig.toByteArray(); String fingerprint = "error!"; try {// w ww.j a v a 2s.c om MessageDigest digest = MessageDigest.getInstance(type); if (digest != null) { byte[] digestBytes = digest.digest(hexBytes); StringBuilder sb = new StringBuilder(); for (byte digestByte : digestBytes) { sb.append((Integer.toHexString((digestByte & 0xFF) | 0x100)).substring(1, 3)); } fingerprint = sb.toString(); } } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return fingerprint; }
From source file:org.opencb.commons.utils.CryptoUtils.java
public static byte[] encryptSha1(String strToEncrypt) { byte[] digest = null; try {//from ww w. jav a2s . c o m MessageDigest instance = MessageDigest.getInstance("SHA-256"); digest = instance.digest(strToEncrypt.getBytes()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return digest; }
From source file:com.lingxiang2014.util.RSAUtils.java
public static KeyPair generateKeyPair() { try {//from w w w. j av a2 s . com KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA", PROVIDER); keyPairGenerator.initialize(KEY_SIZE, new SecureRandom()); return keyPairGenerator.generateKeyPair(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); return null; } }
From source file:Main.java
public static byte[] hash(String message) { MessageDigest cript = null;/*from ww w . j a v a 2 s. co m*/ try { cript = MessageDigest.getInstance("SHA-1"); } catch (NoSuchAlgorithmException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } cript.reset(); try { cript.update(message.getBytes("utf8")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); return null; } return cript.digest(); }
From source file:support.AuthManager.java
public static String md5Custom(String st) { MessageDigest messageDigest = null; byte[] digest = new byte[0]; try {//from ww w .java 2s . c om messageDigest = MessageDigest.getInstance("MD5"); messageDigest.reset(); messageDigest.update(st.getBytes(StandardCharsets.UTF_8)); digest = messageDigest.digest(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } BigInteger bigInt = new BigInteger(1, digest); String md5Hex = bigInt.toString(16); while (md5Hex.length() < 32) { md5Hex = "0" + md5Hex; } return md5Hex; }
From source file:Main.java
public static String enCrypto(String txt, String key) { if (txt != null && !"".equals(txt) && !"null".equals(txt)) { try {//from w w w. j a v a2s.c o m StringBuffer sb = new StringBuffer(); DESKeySpec desKeySpec = new DESKeySpec(key.getBytes()); SecretKeyFactory skeyFactory = null; Cipher cipher = null; try { skeyFactory = SecretKeyFactory.getInstance("DES"); cipher = Cipher.getInstance("DES"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } SecretKey deskey = skeyFactory.generateSecret(desKeySpec); cipher.init(Cipher.ENCRYPT_MODE, deskey); byte[] cipherText = cipher.doFinal(txt.getBytes()); for (int n = 0; n < cipherText.length; n++) { String stmp = (java.lang.Integer.toHexString(cipherText[n] & 0XFF)); if (stmp.length() == 1) { sb.append("0" + stmp); } else { sb.append(stmp); } } return sb.toString().toUpperCase(Locale.US); } catch (Exception e) { e.printStackTrace(); } } return null; }
From source file:Main.java
public static String getFileMacEncrypt(File file, SecretKey key) throws IOException { String algorithm = key.getAlgorithm(); Mac mac = null;/* w w w. j a v a 2 s . c o m*/ try { mac = Mac.getInstance(algorithm); mac.init(key); FileInputStream in = new FileInputStream(file); byte[] buffer = new byte[1024 * 1024]; int len = 0; while ((len = in.read(buffer)) > 0) { mac.update(buffer, 0, len); } in.close(); return bytes2String(mac.doFinal()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (InvalidKeyException e) { e.printStackTrace(); } return null; }
From source file:com.mingsoft.weixin.http.WeixinSSLSocketFactory.java
private static SSLContext createSContext() { SSLContext sslcontext = null; try {/*from www.j a va2 s. co m*/ sslcontext = SSLContext.getInstance("SSL"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } try { sslcontext.init(null, new TrustManager[] { new TrustAnyTrustManager() }, null); } catch (KeyManagementException e) { e.printStackTrace(); return null; } return sslcontext; }
From source file:Main.java
private static byte[] computeHash(String x) { java.security.MessageDigest d = null; try {//from w ww . ja v a2s.co m d = java.security.MessageDigest.getInstance("SHA-1"); d.reset(); d.update(x.getBytes()); return d.digest(); } catch (NoSuchAlgorithmException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } }