List of usage examples for java.security NoSuchAlgorithmException getMessage
public String getMessage()
From source file:es.javocsoft.android.lib.toolbox.ads.AdBase.java
private static final String md5(final String s) { try {//from w w w . j av a 2 s .c o m // Create MD5 Hash MessageDigest digest = java.security.MessageDigest.getInstance("MD5"); digest.update(s.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) { Log.e(ToolBox.TAG, "AdMob -> Error doing MD5! [" + e.getMessage() + "].", e); } return ""; }
From source file:com.alu.e3.common.tools.WsseTools.java
public static byte[] getPasswordDigestBytes(String nonce, String created, byte[] passwordBytes) { byte[] nonceBytes = nonce != null ? Base64.decodeBase64(nonce.getBytes()) : null; byte[] createdBytes = created != null ? created.getBytes() : null; byte[] bytes = concatenate(nonceBytes, createdBytes, passwordBytes); try {//from w w w .j a v a2 s. c o m return Base64.encodeBase64(MessageDigest.getInstance("SHA-1").digest(bytes)); } catch (NoSuchAlgorithmException e) { LOG.error(e.getMessage(), e); throw new RuntimeException(e); // missing message digest algorithm -- should not happen } }
From source file:aaf.vhr.crypto.GoogleAuthenticator.java
/** * Generate a random secret key. This must be saved by the server and associated with the * users account to verify the code displayed by Google Authenticator. * The user must register this secret on their device. * @return secret key/*w w w . j a v a 2 s. c om*/ */ public static String generateSecretKey() { try { SecureRandom sr = SecureRandom.getInstance("SHA1PRNG"); Base32 codec = new Base32(); byte[] buffer = new byte[10]; sr.nextBytes(buffer); byte[] bEncodedKey = codec.encode(buffer); String encodedKey = new String(bEncodedKey); return encodedKey; } catch (NoSuchAlgorithmException e) { e.printStackTrace(); throw new RuntimeException(e.getMessage()); } }
From source file:net.firejack.platform.core.utils.SecurityHelper.java
/** * return hash// ww w .j a v a 2 s . com * * @param plainText value to hash * @return hashed value */ public static String hashMD5(String plainText) { MessageDigest md; try { md = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e.getMessage()); } try { md.update(plainText.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e.getMessage()); } byte raw[] = md.digest(); return (new BASE64Encoder()).encode(raw); }
From source file:net.firejack.platform.core.utils.SecurityHelper.java
/** * return hash/*from ww w. j a va2 s . c o m*/ * * @param plainText value to hash * @return hashed value */ public static String hashSHA(String plainText) { MessageDigest md; try { md = MessageDigest.getInstance("SHA"); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e.getMessage()); } try { md.update(plainText.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e.getMessage()); } byte raw[] = md.digest(); return (new BASE64Encoder()).encode(raw); }
From source file:org.silverpeas.core.io.file.ImageCache.java
private static String hash(String name) { MessageDigest m;/*from w ww . j ava 2 s. c o m*/ try { m = MessageDigest.getInstance("MD5"); m.update(name.getBytes(), 0, name.length()); return new BigInteger(1, m.digest()).toString(16); } catch (NoSuchAlgorithmException e) { SilverLogger.getLogger(ImageCache.class).warn(e.getMessage()); return String.valueOf(name.hashCode()); } }
From source file:com.liferay.util.Encryptor.java
public static String digest(String algorithm, String text) { MessageDigest mDigest = null; try {/* www.j ava 2 s . co m*/ mDigest = MessageDigest.getInstance(algorithm); mDigest.update(text.getBytes(ENCODING)); } catch (NoSuchAlgorithmException nsae) { Logger.error(Encryptor.class, nsae.getMessage(), nsae); } catch (UnsupportedEncodingException uee) { Logger.error(Encryptor.class, uee.getMessage(), uee); } byte raw[] = mDigest.digest(); return Base64.encode(raw); }
From source file:com.proctorcam.proctorserv.HashedAuthenticator.java
/** * buildSig takes query(StringBuilder) as a parameter. After hashing query * in Hex, the resulting signature (String) is returned. *//*w w w. j a va2s . com*/ protected static String buildSig(StringBuilder query) { MessageDigest sha = null; try { sha = MessageDigest.getInstance("SHA-256"); } catch (NoSuchAlgorithmException ex) { System.err.println(ex.getMessage()); } byte[] hash = null; try { hash = sha.digest((query.toString()).getBytes("UTF-8")); } catch (UnsupportedEncodingException ex) { System.err.println(ex.getMessage()); } return new Hex().encodeHexString(hash); }
From source file:org.jwifisd.eyefi.Main.java
public static byte[] md5(byte[]... args) { try {//from w w w.j a va 2 s . c om MessageDigest digest = MessageDigest.getInstance("MD5"); for (byte[] arg : args) { digest.update(arg); } return digest.digest(); } catch (NoSuchAlgorithmException ex) { throw new RuntimeException(ex.getMessage()); } }
From source file:com.fengduo.bee.commons.security.Digests.java
/** * ??//from w w w .j av a 2 s.com * * @param algorithm * @return * @throws RuntimeException {@link java.security.NoSuchAlgorithmException} ? */ private static byte[] getHmacKey(String algorithm) { // ?KeyGenerator KeyGenerator keyGenerator = null; try { keyGenerator = KeyGenerator.getInstance(algorithm); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e.getMessage()); } // SecretKey secretKey = keyGenerator.generateKey(); // return secretKey.getEncoded(); }