Example usage for java.security NoSuchAlgorithmException getMessage

List of usage examples for java.security NoSuchAlgorithmException getMessage

Introduction

In this page you can find the example usage for java.security NoSuchAlgorithmException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.openbravo.utils.CryptoSHA1BASE64.java

public static String hash(String plaintext) throws ServletException {
    MessageDigest md = null;/*from  www.j  av  a 2s  .c  o m*/

    try {
        md = MessageDigest.getInstance("SHA"); // SHA-1 generator instance
    } catch (NoSuchAlgorithmException e) {
        throw new ServletException(e.getMessage());
    }

    try {
        md.update(plaintext.getBytes("UTF-8")); // Message summary
        // generation
    } catch (UnsupportedEncodingException e) {
        throw new ServletException(e.getMessage());
    }

    byte raw[] = md.digest(); // Message summary reception
    try {
        String hash = new String(org.apache.commons.codec.binary.Base64.encodeBase64(raw), "UTF-8");
        return hash;
    } catch (UnsupportedEncodingException use) {
        throw new ServletException(use);
    }
}

From source file:com.likya.tlos.utils.PasswordService.java

public static synchronized String encrypt(String plaintext) throws Exception {
    MessageDigest md = null;/*w  w w . j a  va2  s  .co m*/
    try {
        md = MessageDigest.getInstance("SHA"); // step 2 //$NON-NLS-1$
    } catch (NoSuchAlgorithmException e) {
        throw new Exception(e.getMessage());
    }
    try {
        md.update(plaintext.getBytes("UTF-8")); // step 3 //$NON-NLS-1$
    } catch (UnsupportedEncodingException e) {
        throw new Exception(e.getMessage());
    }
    byte raw[] = md.digest(); // step 4

    /**
     * Sun uygulamasndan vazgeilip apache uygulamas kullanld
     * 16.03.2011 
     * 
     */
    // String hash = (new BASE64Encoder()).encode(raw); // step 5

    String hash = Base64.encodeBase64String(raw);

    return hash; // step 6
}

From source file:com.ksc.internal.SdkSSLContext.java

/**
 * @see SSLContexts#createDefault()/* w  w  w  . j  a  v  a  2  s  .c o m*/
 */
public static final SSLContext getPreferredSSLContext(final SecureRandom secureRandom) {
    try {
        final SSLContext sslcontext = SSLContext.getInstance("TLS");
        // http://download.java.net/jdk9/docs/technotes/guides/security/jsse/JSSERefGuide.html
        sslcontext.init(null, null, secureRandom);
        return sslcontext;
    } catch (final NoSuchAlgorithmException ex) {
        throw new SSLInitializationException(ex.getMessage(), ex);
    } catch (final KeyManagementException ex) {
        throw new SSLInitializationException(ex.getMessage(), ex);
    }
}

From source file:HashUtil.java

public static String getMD5(final String data) {
    try {//from  www  .j  av a2s  .  co m
        MessageDigest m = MessageDigest.getInstance("MD5");
        m.reset();
        m.update(data.getBytes());
        BigInteger bigInt = new BigInteger(1, m.digest());
        String hashtext = bigInt.toString(16);
        while (hashtext.length() < 32) {
            hashtext = "0" + hashtext;
        }
        return hashtext;
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
        return e.getMessage();
    }
}

From source file:no.sesat.search.security.MD5Generator.java

/**
 * Returns a MessageDigest for the given <code>algorithm</code>.
 *
 * @param algorithm The MessageDigest algorithm name.
 * @return An digest instance./*from ww w .ja v  a2 s. c  o m*/
 * @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.myjeeva.spring.security.util.SpringExtensionsUtil.java

/**
 * generates the MD5 Hash value from given salt value
 * /* w  w w.  j  a v  a2 s  . co m*/
 * @param md5Salt - a {@link java.lang.String} object.
 * @return md5 hash value if success, <code>null</code> if exception/fails
 */
public static String getMD5(String md5Salt) {
    try {
        MessageDigest md = MessageDigest.getInstance(MD5);
        byte[] array = md.digest(md5Salt.getBytes(UTF8));
        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) {
        LOG.error(e.getMessage());
    } catch (UnsupportedEncodingException e) {
        LOG.error(e.getMessage());
    }
    return null;
}

From source file:auguste.client.command.client.AccountCreate.java

private static String hashPassword(String password) {
    try {/*from  w  ww .ja va  2  s  .  com*/
        MessageDigest digest = MessageDigest.getInstance("SHA-1");
        digest.reset();
        digest.update(password.getBytes());
        return new String(Hex.encodeHex(digest.digest()));
    } catch (NoSuchAlgorithmException e) {
        // Algorithme indisponible
        System.out.println(e.getMessage());
        return new String();
    }
}

From source file:org.agora.server.Util.java

public static String hash(String password) {
    try {//from w ww. j a  v  a2 s .  c  o  m
        MessageDigest md = MessageDigest.getInstance("SHA-256");
        byte[] hash = md.digest(password.getBytes(Charset.forName("UTF-8")));

        return Base64.encodeBase64String(hash);
    } catch (NoSuchAlgorithmException e) {
        Log.error("[Util.hashPassword] Error hashing password (" + e.getMessage() + ")");
        return null;
    }
}

From source file:it.paolorendano.clm.util.Utils.java

/**
 * Hash password.//  w w  w  .  j a  v  a2 s  .  c  o m
 *
 * @param password the password
 * @return the string
 */
public static String hashPassword(String password) {
    MessageDigest mdigest;
    try {
        mdigest = MessageDigest.getInstance("SHA-256");
        mdigest.update(password.getBytes("UTF-8"));
        return Base64.encodeBase64String(mdigest.digest());
    } catch (NoSuchAlgorithmException e) {
        if (LOGGER.isErrorEnabled())
            LOGGER.error(e.getMessage(), e);
    } catch (UnsupportedEncodingException e) {
        if (LOGGER.isErrorEnabled())
            LOGGER.error(e.getMessage(), e);
    }
    return null;
}

From source file:org.nuclos.common.CryptUtil.java

public static byte[] digestOf(byte[] content) {
    try {//from   ww w  .j a  v  a 2  s  . c  o  m
        final MessageDigest digest = MessageDigest.getInstance("SHA-1");
        digest.reset();
        digest.update(content);
        return digest.digest();
    } catch (NoSuchAlgorithmException e) {
        throw new CommonFatalException(e.getMessage(), e);
    }
}