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:org.gatherdata.commons.security.DigestFactory.java

public static byte[] createDigestFor(Collection<? extends Serializable> data) {

    byte[] digest = null;
    try {//from   www .j  a  v a 2 s  .  c  om
        digest = createDigestFor(data, defaultAlgorithm);
    } catch (NoSuchAlgorithmException e) {
        System.err.println("Default algorithm \"" + defaultAlgorithm + "\" not recognized by MessageDigest");
        e.printStackTrace();
    }
    return digest;
}

From source file:com.distimo.sdk.Utils.java

static String md5(String s) {
    if (Utils.DEBUG) {
        Log.i(TAG, "md5()");
    }// w ww .  j  a v a 2 s.c om

    String result = "";

    MessageDigest m = null;
    try {
        m = MessageDigest.getInstance("MD5");
        m.update(s.getBytes(), 0, s.length());
        result = byteArrayToHexString(m.digest());
    } catch (final NoSuchAlgorithmException nsae) {
        if (Utils.DEBUG) {
            nsae.printStackTrace();
        }
    }

    return result;
}

From source file:net.blogracy.controller.FileSharing.java

public static String hash(String text) {
    String result = null;//from w w  w . jav a2s.c  om
    try {
        MessageDigest digester = MessageDigest.getInstance("SHA-1");
        Base32 encoder = new Base32();
        byte[] digest = digester.digest(text.getBytes());
        result = encoder.encodeAsString(digest);
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    return result;
}

From source file:org.gatherdata.commons.security.Seal.java

/**
 * Factory method to construct a new Seal using the default algorithm.
 * /*from ww w .  ja  v a  2s  .  co  m*/
 * @param data data to be sealed
 * @return
 */
public static Seal createSealFor(Serializable data) {
    Seal dataSeal = null;
    try {
        dataSeal = createSealFor(data, defaultAlgorithm);
    } catch (NoSuchAlgorithmException e) {
        System.err.println("Default algorithm \"" + defaultAlgorithm + "\" not recognized by MessageDigest");
        e.printStackTrace();
    }
    return dataSeal;
}

From source file:com.beetle.framework.util.OtherUtil.java

public static final byte[] md5(String str) {

    java.security.MessageDigest digest;
    try {/* www  .j av  a  2s . c o  m*/
        digest = java.security.MessageDigest.getInstance("MD5");
        return digest.digest(str.getBytes());
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:edu.hku.sdb.udf.util.UDFHandler.java

private static boolean search(byte[] encrypted, String keyword, SecretKey prkey) {
    byte[] keywordbyte = keyword.getBytes();
    if (keywordbyte.length != encrypted.length) {
        return false;
    }//from ww  w. j  av  a2  s. co m
    byte[] diff1 = new byte[keywordbyte.length - 1];
    for (int i = 0; i < diff1.length; i++) {
        diff1[i] = (byte) (encrypted[i] ^ keywordbyte[i]);
    }
    byte diff2 = (byte) (encrypted[diff1.length] ^ keywordbyte[diff1.length]);
    // get diff = word xor encrypted
    // if it is a match, first part of diff generates second part of diff using pseudo random function

    try {
        // pseudorandom cipher
        Cipher prCipher = Cipher.getInstance(SCHEME);
        prCipher.init(Cipher.ENCRYPT_MODE, prkey);

        // si is chopped with the desired length

        byte[] fksi = prCipher.doFinal(diff1);
        // fksi is F_k(S_i) in the searchable encryption
        // we use the same AES cipher for simplicity

        return fksi[0] == diff2;
    } catch (NoSuchAlgorithmException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (NoSuchPaddingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InvalidKeyException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalBlockSizeException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (BadPaddingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return false;
}

From source file:jp.go.nict.langrid.management.web.utility.StringUtil.java

/**
 * //from  ww w .j  a va  2s  . c o m
 * 
 */
public static String getUniqueString() {
    MessageDigest sha;
    try {
        sha = MessageDigest.getInstance("SHA-1");
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
        return "";
    }
    sha.reset();
    sha.update(String.valueOf(Math.random()).getBytes());
    byte[] hash = sha.digest();
    StringBuffer sb = new StringBuffer();
    int cnt = hash.length;
    for (int i = 0; i < cnt; i++) {
        int d = hash[i];
        if (d < 0) {
            d += 256;
        }
        sb.append(Integer.toHexString(d & 0x0F));
    }
    return sb.toString();
}

From source file:com.savor.ads.core.ApiRequestFactory.java

public static String md5(String input) {
    try {/*  www  .  j  a  v a 2  s .  c o  m*/
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        md5.update(input.getBytes());
        byte[] result = md5.digest();//
        return StringUtils.toHexString(result, false);
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:utils.HttpClientGenerator.java

public static CloseableHttpClient getHttpClient(boolean checkCert) {

    if (checkCert == false) {
        HttpClientBuilder b = HttpClientBuilder.create();

        // setup a Trust Strategy that allows all certificates.
        SSLContext sslContext = null;
        try {//from  w  w  w.j ava 2s . c o m
            sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
                public boolean isTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
                    return true;
                }
            }).build();
        } catch (NoSuchAlgorithmException e) {
            String err = "error occurred while creating SSL disables hhtp client";
        } catch (KeyManagementException e) {
            e.printStackTrace();
        } catch (KeyStoreException e) {
            e.printStackTrace();
        }
        b.setSslcontext(sslContext);

        // not to check Hostnames
        HostnameVerifier hostnameVerifier = SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;

        //       create an SSL Socket Factory, to use weakened "trust strategy";
        //       and create a Registry, to register it.
        SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext,
                (X509HostnameVerifier) hostnameVerifier);
        Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder
                .<ConnectionSocketFactory>create()
                .register("http", PlainConnectionSocketFactory.getSocketFactory())
                .register("https", sslSocketFactory).build();

        // creating connection-manager using our Registry.
        //      -- allows multi-threaded use
        PoolingHttpClientConnectionManager connMgr = new PoolingHttpClientConnectionManager(
                socketFactoryRegistry);
        connMgr.setDefaultMaxPerRoute(20);
        // Increase max connections for localhost:80 to 50
        HttpHost localhost = new HttpHost("localhost", 9443);
        connMgr.setMaxPerRoute(new HttpRoute(localhost), 10);
        b.setConnectionManager(connMgr);

        // finally, build the HttpClient;
        CloseableHttpClient client = b.build();
        return client;
    } else {
        PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
        // Increase default max connection per route to 20
        cm.setDefaultMaxPerRoute(20);
        // Increase max connections for localhost:80 to 50
        HttpHost localhost = new HttpHost("localhost", 9443);
        cm.setMaxPerRoute(new HttpRoute(localhost), 10);
        CloseableHttpClient client = HttpClients.custom().setConnectionManager(cm).build();
        return client;
    }
}

From source file:org.kurento.modulecreator.Main.java

private static void printSimpleKmd(KurentoModuleCreator krp, CommandLine line)
        throws FileNotFoundException, IOException {
    if (!line.hasOption(PRINT_SIMPLE_KMD)) {
        return;//from  ww w .ja v  a  2  s  .  c om
    }

    try {
        krp.printSimpleKmd();
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    System.exit(0);
}