Example usage for java.security NoSuchAlgorithmException toString

List of usage examples for java.security NoSuchAlgorithmException toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:Main.java

private static byte[] getKeyBytes(String mykey) {
    try {/*w  w  w .j  a  v  a2 s  . co  m*/
        MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
        digest.update(mykey.getBytes(Charset.forName("UTF-8")));
        return digest.digest();
    } catch (NoSuchAlgorithmException e) {
        Log.e(TAG, "Password creation exception: " + e.toString());
        return errorbyte;
    }
}

From source file:Main.java

public static String getMD5(String mykey) {
    try {//from  w  w  w  . ja  v  a  2  s . c  o  m
        MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
        digest.update(mykey.getBytes(Charset.forName("UTF-8")));
        return bytesToHex(digest.digest()).toLowerCase();
    } catch (NoSuchAlgorithmException e) {
        Log.e(TAG, "MD5 hash exception: " + e.toString());
        return null;
    }
}

From source file:Main.java

public static String getSHA256(byte[] mydata) {
    try {//w ww. j  av  a 2s . c o  m
        MessageDigest digest = java.security.MessageDigest.getInstance("SHA256");
        digest.update(mydata);
        return bytesToHex(digest.digest()).toLowerCase();
    } catch (NoSuchAlgorithmException e) {
        Log.e(TAG, "SHA hash exception: " + e.toString());
        return null;
    }
}

From source file:Main.java

public static String getSHA256(String mykey) {
    try {// w ww .  j  a  v  a2  s . c o  m
        MessageDigest digest = java.security.MessageDigest.getInstance("SHA256");
        digest.update(mykey.getBytes(Charset.forName("UTF-8")));
        return bytesToHex(digest.digest()).toLowerCase();
    } catch (NoSuchAlgorithmException e) {
        Log.e(TAG, "SHA hash exception: " + e.toString());
        return null;
    }
}

From source file:Main.java

public static String getHash(String text) {
    try {// w w w .  j av  a 2s.  c  o  m
        return SHA1(text);
    } catch (NoSuchAlgorithmException e) {
        Log.e(LOGTAG, "NoSuchAlgorithmException: " + e.toString(), e);

        return null; // FIXME: add other hash logic
    }
}

From source file:org.starfishrespect.myconsumption.android.util.CryptoUtils.java

/**
 * Return a Base64 encoded String of the hash(input) (SHA 256)
 * @param input a String to encode/*  w  w  w .  j a  v a  2  s.c o  m*/
 * @return a Base64 encoded String of the hash(input) (SHA 256)
 */
public static String sha256(String input) {
    MessageDigest digest = null;
    try {
        digest = MessageDigest.getInstance("SHA-256");
    } catch (NoSuchAlgorithmException e) {
        LOGE(TAG, e.toString());
    }
    byte[] hash = new byte[0];
    if (digest != null) {
        try {
            hash = digest.digest(input.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            LOGE(TAG, e.toString());
        }

    }
    return Base64.encodeToString(hash, Base64.NO_WRAP);
}

From source file:photosharing.api.ExecutorUtil.java

/**
 * helper method that returns an HTTPClient executor with credentials
 * available./*from w w w . j  a va 2  s .c o  m*/
 * 
 * Also enables the test case to connect to ANY SSL Certificate
 * valid/invalid
 * 
 * @return {Executor} or Null if there is an issue
 */
public static Executor getExecutor() {
    Executor executor = null;

    /*
     * if using one of the environments without a trusted CA chain or
     * you are using Fiddler, you want to set TRUST=TRUE in appconfig.properties
     */
    Configuration config = Configuration.getInstance(null);
    String sTrust = config.getValue(Configuration.TRUST);
    boolean trusted = Boolean.parseBoolean(sTrust);
    if (trusted) {
        try {
            HttpClientBuilder builder = HttpClients.custom();

            // Setup the SSL Context to Trust Any SSL Certificate
            SSLContextBuilder sslBuilder = new SSLContextBuilder();
            sslBuilder.loadTrustMaterial(null, new TrustStrategy() {
                /**
                 * override for fiddler proxy
                 */
                public boolean isTrusted(X509Certificate[] certs, String host) throws CertificateException {
                    return true;
                }
            });
            SSLContext sslContext = sslBuilder.build();
            builder.setHostnameVerifier(new AllowAllHostnameVerifier());
            builder.setSslcontext(sslContext);

            CloseableHttpClient httpClient = builder.build();
            executor = Executor.newInstance(httpClient);
        } catch (NoSuchAlgorithmException e) {
            logger.log(Level.SEVERE, "Issue with No Algorithm " + e.toString());
        } catch (KeyStoreException e) {
            logger.log(Level.SEVERE, "Issue with KeyStore " + e.toString());
        } catch (KeyManagementException e) {
            logger.log(Level.SEVERE, "Issue with KeyManagement  " + e.toString());
        }
    }

    return executor;
}

From source file:org.fusesource.meshkeeper.classloader.basic.BasicClassLoaderFactory.java

static byte[] fingerprint(InputStream is) throws IOException {
    try {/* w  w  w  .  j  a v  a  2  s  .  c o m*/
        MessageDigest md = MessageDigest.getInstance("SHA-1");
        byte buffer[] = new byte[1024 * 4];
        int c;
        while ((c = is.read(buffer)) > 0) {
            md.update(buffer, 0, c);
        }
        return md.digest();
    } catch (NoSuchAlgorithmException e) {
        throw new IOException(e.toString());
    } finally {
        try {
            is.close();
        } catch (IOException ignore) {
        }
    }
}

From source file:org.godotengine.godot.Utils.java

public static final String md5(final String s) {
    try {/*from ww w  . ja v  a2s  . co  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) {
        w("FB:MD5:Algorithm:" + e.toString());
    }

    return "";
}

From source file:com.sixsq.slipstream.cookie.CryptoUtils.java

/**
 * Determine if the given signature matches the given data.
 *
 * @param signed/*  w  ww .  j a va  2s .c o m*/
 *            String representation of signature
 * @param data
 *            information to check
 *
 * @return true if the signature matches the given data, false otherwise
 */
public static boolean verify(String signed, String data) {

    boolean valid = false;

    try {

        Signature signature = Signature.getInstance(signatureAlgorithm);
        signature.initVerify(publicKey);

        signature.update(data.getBytes());

        byte[] signBytes = (new BigInteger(signed, radix)).toByteArray();
        valid = signature.verify(signBytes);

    } catch (NoSuchAlgorithmException e) {
        log.warning("Algorithm not recognized: " + signatureAlgorithm + " with details: " + e.getMessage());
    } catch (InvalidKeyException e) {
        log.warning(e.toString());
    } catch (SignatureException e) {
        log.warning(e.toString());
    }

    return valid;
}