List of usage examples for java.security NoSuchAlgorithmException getMessage
public String getMessage()
From source file:org.drdevelopment.webtool.util.FileUtil.java
public static String getMD5(String source) { try {//from w ww. j ava 2 s. com MessageDigest md = MessageDigest.getInstance("MD5"); md.update(source.getBytes()); byte[] hash = md.digest(); StringBuilder hexString = new StringBuilder(); for (int i = 0; i < hash.length; i++) { if ((0xff & hash[i]) < 0x10) { hexString.append("0" + Integer.toHexString((0xFF & hash[i]))); } else { hexString.append(Integer.toHexString(0xFF & hash[i])); } } return hexString.toString(); } catch (NoSuchAlgorithmException e) { LOGGER.error(e.getMessage(), e); } return null; }
From source file:venuproject.uwf.edu.LDAPProcessor.java
private static String encrypt(String plaintext) { MessageDigest md = null;//from w w w . j a va 2s. com 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(); String hash = "{SHA}" + (new BASE64Encoder()).encode(raw); return hash; }
From source file:com.fizzed.rocker.compiler.RockerUtil.java
static public String md5(File f) throws IOException { try {//from ww w . java 2 s.c o m byte[] b = Files.readAllBytes(f.toPath()); byte[] hash = MessageDigest.getInstance("MD5").digest(b); return byteArrayToHex(hash); } catch (NoSuchAlgorithmException e) { throw new IOException(e.getMessage(), e); } }
From source file:org.jwifisd.eyefi.EyeFiServer.java
/** * calculate the md5 of all the byte arrays specified as parameters. * /* w w w .ja va2 s . co m*/ * @param args * the byte arrays to create the md5 over * @return the md5 digest. */ public static byte[] md5(byte[]... args) { try { 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:edu.tum.cs.ias.knowrob.utils.ResourceRetriever.java
/** * Calculate MD5 checksum of the given string. * // ww w. j av a 2 s .co m * @param md5 * Value to calculate md5 for. * @return null if encoding unsupported or algorithm not found */ private static String MD5(String md5) { try { java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5"); byte[] array = md.digest(md5.getBytes("UTF-8")); StringBuffer sb = new StringBuffer(); for (int i = 0; i < array.length; ++i) { sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1, 3)); } return sb.toString(); } catch (java.security.NoSuchAlgorithmException e) { System.err.println("ResourceRetriever NoSuchAlgorithmException Error: " + e.getMessage()); } catch (UnsupportedEncodingException e) { System.err.println("ResourceRetriever UnsupportedEncodingException Error: " + e.getMessage()); } return null; }
From source file:org.wso2.carbon.identity.mgt.util.Utils.java
/** * @param value//from w ww.j a v a 2s . c o m * @return * @throws UserStoreException */ public static String doHash(String value) throws UserStoreException { try { String digsestFunction = "SHA-256"; MessageDigest dgst = MessageDigest.getInstance(digsestFunction); byte[] byteValue = dgst.digest(value.getBytes()); return Base64.encode(byteValue); } catch (NoSuchAlgorithmException e) { log.error(e.getMessage(), e); throw new UserStoreException(e.getMessage(), e); } }
From source file:DigestUtils.java
/** * Returns a MessageDigest for the given <code>algorithm</code>. * //from www.j ava 2 s . c om * @param algorithm * The MessageDigest algorithm name. * @return An MD5 digest instance. * @throws RuntimeException * when a {@link java.security.NoSuchAlgorithmException} is caught, */ static MessageDigest getDigest(String algorithm) { try { return MessageDigest.getInstance(algorithm); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e.getMessage()); } }
From source file:com.netflix.client.ssl.URLSslContextFactory.java
/** * Opens the specified key or trust store using the given password. * * In case of failure {@link com.netflix.client.ssl.ClientSslSocketFactoryException} is thrown, and wrapps the * underlying cause exception. That could be: * <ul>/* w w w .jav a 2 s. co m*/ * <li>KeyStoreException if the JRE doesn't support the standard Java Keystore format, in other words: never</li> * <li>NoSuchAlgorithmException if the algorithm used to check the integrity of the keystore cannot be found</li> * <li>CertificateException if any of the certificates in the keystore could not be loaded</li> * <li> * IOException if there is an I/O or format problem with the keystore data, if a * password is required but not given, or if the given password was incorrect. If the * error is due to a wrong password, the cause of the IOException should be an UnrecoverableKeyException. * </li> * </ul> * * @param storeFile the location of the store to load * @param password the password protecting the store * @return the newly loaded key store * @throws ClientSslSocketFactoryException a wrapper exception for any problems encountered during keystore creation. */ private static KeyStore createKeyStore(final URL storeFile, final String password) throws ClientSslSocketFactoryException { if (storeFile == null) { return null; } Preconditions.checkArgument(StringUtils.isNotEmpty(password), "Null keystore should have empty password, defined keystore must have password"); KeyStore keyStore = null; try { keyStore = KeyStore.getInstance("jks"); InputStream is = storeFile.openStream(); try { keyStore.load(is, password.toCharArray()); } catch (NoSuchAlgorithmException e) { throw new ClientSslSocketFactoryException( String.format("Failed to create a keystore that supports algorithm %s: %s", SOCKET_ALGORITHM, e.getMessage()), e); } catch (CertificateException e) { throw new ClientSslSocketFactoryException(String.format( "Failed to create keystore with algorithm %s due to certificate exception: %s", SOCKET_ALGORITHM, e.getMessage()), e); } finally { try { is.close(); } catch (IOException ignore) { // NOPMD } } } catch (KeyStoreException e) { throw new ClientSslSocketFactoryException( String.format("KeyStore exception creating keystore: %s", e.getMessage()), e); } catch (IOException e) { throw new ClientSslSocketFactoryException( String.format("IO exception creating keystore: %s", e.getMessage()), e); } return keyStore; }
From source file:cn.mrdear.pay.util.RSAUtils.java
/** * ?//from w w w .j av a 2s .c o m * * @param keySize * ? * @return */ public static KeyPair generateKeyPair(int keySize) { Assert.state(keySize > 0); try { KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(KEY_ALGORITHM, PROVIDER); keyPairGenerator.initialize(keySize); return keyPairGenerator.generateKeyPair(); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e.getMessage(), e); } }
From source file:cn.mrdear.pay.util.RSAUtils.java
/** * ??/*from w w w .j a v a 2s. com*/ * * @param encodedKey * ? * @return ? */ public static PrivateKey generatePrivateKey(byte[] encodedKey) { try { KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM, PROVIDER); return keyFactory.generatePrivate(new PKCS8EncodedKeySpec(encodedKey)); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e.getMessage(), e); } catch (InvalidKeySpecException e) { throw new RuntimeException(e.getMessage(), e); } }