Example usage for java.security NoSuchAlgorithmException printStackTrace

List of usage examples for java.security NoSuchAlgorithmException printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:com.aqnote.shared.cryptology.digest.SHA.java

public final static String sha384(byte[] src) {
    if (src == null)
        return "";
    try {/*from   w ww.j  a  v a2  s  .  co  m*/
        // MessageDigest md = MessageDigest.getInstance("SHA-384");
        MessageDigest md = MessageDigest.getInstance(OID_SHA2_384, JCE_PROVIDER);
        md.update(src);
        return new String(ByteUtil.toHexBytes(md.digest()));
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (NoSuchProviderException e) {
        e.printStackTrace();
    }
    return "";
}

From source file:com.aqnote.shared.cryptology.digest.SHA.java

public final static String sha512(byte[] src) {
    if (src == null)
        return "";
    try {//w w w .j a v a2 s  .  c  o m
        // MessageDigest md = MessageDigest.getInstance("SHA-512");
        MessageDigest md = MessageDigest.getInstance(OID_SHA2_512, JCE_PROVIDER);
        md.update(src);
        return new String(ByteUtil.toHexBytes(md.digest()));
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (NoSuchProviderException e) {
        e.printStackTrace();
    }
    return "";
}

From source file:com.aqnote.shared.cryptology.digest.SHA.java

public final static String sha512_224(byte[] src) {
    if (src == null)
        return "";
    try {/*from ww  w .  ja va2s . c om*/
        // MessageDigest md = MessageDigest.getInstance("SHA-512/256");
        MessageDigest md = MessageDigest.getInstance(OID_SHA2_512_224, JCE_PROVIDER);
        md.update(src);
        return new String(ByteUtil.toHexBytes(md.digest()));
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (NoSuchProviderException e) {
        e.printStackTrace();
    }
    return "";
}

From source file:com.aqnote.shared.cryptology.digest.SHA.java

public final static String sha512_256(byte[] src) {
    if (src == null)
        return "";
    try {// w w w. j  av a 2  s. c  o  m
        // MessageDigest md = MessageDigest.getInstance("SHA-512/256");
        MessageDigest md = MessageDigest.getInstance(OID_SHA2_512_256, JCE_PROVIDER);
        md.update(src);
        return new String(ByteUtil.toHexBytes(md.digest()));
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (NoSuchProviderException e) {
        e.printStackTrace();
    }
    return "";
}

From source file:com.aqnote.shared.cryptology.digest.SHA.java

public final static String sha224(byte[] src) {
    if (src == null)
        return "";
    try {/*from  www  . j a  v a 2s . c o m*/
        // MessageDigest md = MessageDigest.getInstance("SHA-224",
        // JCE_PROVIDER);
        MessageDigest md = MessageDigest.getInstance(OID_SHA2_224, JCE_PROVIDER);
        md.update(src);
        return new String(ByteUtil.toHexBytes(md.digest()));
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (NoSuchProviderException e) {
        e.printStackTrace();
    }
    return "";
}

From source file:com.aqnote.shared.cryptology.digest.SHA.java

public final static String sha256(byte[] src) {
    if (src == null)
        return "";
    try {//from  ww  w. j a va2  s .co m
        // MessageDigest md = MessageDigest.getInstance("SHA-256",
        // JCE_PROVIDER);
        MessageDigest md = MessageDigest.getInstance(OID_SHA2_256, JCE_PROVIDER);
        md.update(src);
        return new String(ByteUtil.toHexBytes(md.digest()));
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (NoSuchProviderException e) {
        e.printStackTrace();
    }
    return "";
}

From source file:edu.illinois.cs.cogcomp.wikifier.utils.freebase.QueryMQL.java

public static String getMD5Checksum(String query) {
    MessageDigest complete = null;
    try {//from w ww.j ava  2s .  co  m
        complete = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    complete.update(query.getBytes(), 0, query.getBytes().length);
    byte[] b = complete.digest();
    String result = "";
    for (int i = 0; i < b.length; i++)
        result += Integer.toString((b[i] & 0xff) + 0x100, 16).substring(1);
    return result;
}

From source file:com.popcorntime.apps.remote.utils.Utils.java

public static String md5(final String s) {

    final String MD5 = "MD5";
    try {//w w w  . jav  a  2 s.  c o  m
        // Create MD5 Hash
        MessageDigest digest = MessageDigest.getInstance(MD5);
        digest.update(s.getBytes());
        byte messageDigest[] = digest.digest();

        // Create Hex String
        StringBuilder hexString = new StringBuilder();
        for (byte aMessageDigest : messageDigest) {
            String h = Integer.toHexString(0xFF & aMessageDigest);
            while (h.length() < 2)
                h = "0" + h;
            hexString.append(h);
        }
        return hexString.toString();

    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    return "";
}

From source file:eu.europeana.uim.sugarcrmclient.internal.helpers.ClientUtils.java

/**
 * Encrypts a given String into a MD5 format.
 * /*from w w w.j a  v a  2 s.com*/
 * @param value
 *            The string to be encrypted
 * @return the encrypted String
 */
public static String md5(String value) {
    // MessageDigest mdEnc;
    try {
        MessageDigest md = MessageDigest.getInstance("MD5");
        byte[] messageDigest = md.digest(value.getBytes());
        BigInteger number = new BigInteger(1, messageDigest);
        String hashtext = number.toString(16);
        while (hashtext.length() < 32) {
            hashtext = "0" + hashtext;
        }
        return hashtext;
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }

    return "";
}

From source file:com.piusvelte.hydra.ConnectionManager.java

static String getHash64(String in) {
    String out = null;//  ww  w.j a  v a 2  s  . c om
    MessageDigest md;
    try {
        md = MessageDigest.getInstance("SHA-256");
        md.update(in.getBytes("UTF-8"));
        out = new BigInteger(1, md.digest()).toString(16);
        StringBuffer hexString = new StringBuffer();
        byte[] hash = md.digest();
        for (byte b : hash) {
            if ((0xFF & b) < 0x10)
                hexString.append("0" + Integer.toHexString((0xFF & b)));
            else
                hexString.append(Integer.toHexString(0xFF & b));
        }
        out = hexString.toString();
        if (out.length() > 64)
            return out.substring(0, 64);
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return out;
}