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.tydic.dbp.utils.ThreeDesUtils.java

public static String decryptMode(String srcStr) {
    try {/*from w ww .  ja va  2  s . co  m*/
        // ?
        SecretKey deskey = new SecretKeySpec(keyBytes, Algorithm);
        // 
        Cipher c1 = Cipher.getInstance(Algorithm);
        c1.init(Cipher.DECRYPT_MODE, deskey);
        return new String(c1.doFinal(Hex.decodeHex(srcStr.toCharArray())));
    } catch (java.security.NoSuchAlgorithmException e1) {
        e1.printStackTrace();
    } catch (javax.crypto.NoSuchPaddingException e2) {
        e2.printStackTrace();
    } catch (java.lang.Exception e3) {
        e3.printStackTrace();
    }
    return null;
}

From source file:org.apache.hadoop.hive.ql.udf.UDFMd5Hash.java

private static String getMd5(String toEncrypt) {
    try {/* w  w  w.j a v  a2 s  .co m*/
        byte[] results = MessageDigest.getInstance("MD5").digest(toEncrypt.getBytes());
        String resultString = byteArrayToHexString(results);
        return resultString;
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:org.apache.hadoop.hive.ql.udf.UDFMd5Hash.java

private static String getMd5(byte[] toEncrypt) {
    try {//from   w  w  w  . ja  v  a  2 s  . c om
        byte[] results = MessageDigest.getInstance("MD5").digest(toEncrypt);
        String resultString = byteArrayToHexString(results);
        return resultString;
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

private static byte[] MD5EncodeFileByte(File filename) {
    if (filename != null) {
        int i;/*  www  .  j  ava 2  s. co m*/
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            return null;
        }
        byte[] data = new byte[4096];
        FileInputStream fis;
        try {
            fis = new FileInputStream(filename);
        } catch (FileNotFoundException e2) {
            e2.printStackTrace();
            return null;
        }
        while (true) {
            try {
                i = fis.read(data);
                if (i != -1) {
                    md.update(data, 0, i);
                } else {
                    fis.close();
                    return md.digest();
                }
            } catch (IOException e) {
                e.printStackTrace();
                try {
                    fis.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
                return null;
            }
        }
    }
    return null;
}

From source file:Main.java

private static TrustManager[] prepareTrustManager(InputStream... certificates) {
    if (certificates != null && certificates.length > 0) {
        try {/*from   w  ww  . ja v  a 2s  .c  o  m*/
            CertificateFactory e = CertificateFactory.getInstance("X.509");
            KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
            keyStore.load((KeyStore.LoadStoreParameter) null);
            int index = 0;
            InputStream[] trustManagerFactory = certificates;
            int trustManagers = certificates.length;

            for (int i$ = 0; i$ < trustManagers; ++i$) {
                InputStream certificate = trustManagerFactory[i$];
                String certificateAlias = Integer.toString(index++);
                keyStore.setCertificateEntry(certificateAlias, e.generateCertificate(certificate));

                try {
                    if (certificate != null) {
                        certificate.close();
                    }
                } catch (IOException var10) {
                    ;
                }
            }

            trustManagerFactory = null;
            TrustManagerFactory var15 = TrustManagerFactory
                    .getInstance(TrustManagerFactory.getDefaultAlgorithm());
            var15.init(keyStore);
            TrustManager[] var16 = var15.getTrustManagers();
            return var16;
        } catch (NoSuchAlgorithmException var11) {
            var11.printStackTrace();
        } catch (CertificateException var12) {
            var12.printStackTrace();
        } catch (KeyStoreException var13) {
            var13.printStackTrace();
        } catch (Exception var14) {
            var14.printStackTrace();
        }

        return null;
    } else {
        return null;
    }
}

From source file:com.alta189.deskbin.util.DesEncrypter.java

public static SecretKey getNewKey() {
    try {//w  w  w. jav a  2 s. c  o  m
        return KeyGenerator.getInstance("DES").generateKey();
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:com.konakart.bl.modules.payment.barclaycardsmartpayhosted.BarclaycardSmartPayHostedHMACTools.java

/**
 * Get a HMAC signature using the specified secret 
 * @param secret/*  ww  w .  j  av a  2  s  .c  o m*/
 * @param signingData
 * @return a Base64 encoded signature
 */
public static String getBase64EncodedSignature(String secret, String signingData) {
    SecretKey key = getMacKey(secret);
    try {
        Mac mac = Mac.getInstance(key.getAlgorithm());
        mac.init(getMacKey(secret));
        byte[] digest = mac.doFinal(signingData.getBytes("UTF8"));
        return new String(Base64.encodeBase64(digest), "ASCII");
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (InvalidKeyException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:com.konakart.bl.modules.payment.barclaycardsmartpayhosted.BarclaycardSmartPayHostedHMACTools.java

/**
 * Verify the signature/*w  w w .  j a v a  2s  .  co  m*/
 * @param secret
 * @param sig
 * @param signedData
 * @return true if the signature is verified
 */
public static boolean verifyBase64EncodedSignature(String secret, String sig, String signedData) {
    if (secret == null || sig == null || signedData == null)
        return false;

    SecretKey key = getMacKey(secret);
    try {
        Mac mac = Mac.getInstance(key.getAlgorithm());
        mac.init(getMacKey(secret));
        byte[] digest = mac.doFinal(signedData.getBytes("UTF8"));
        return sig.equals(new String(Base64.encodeBase64(digest), "ASCII"));
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (InvalidKeyException e) {
        e.printStackTrace();
    }
    return false;
}

From source file:Main.java

public static byte[] aesIGEdecrypt(byte[] tmpAESiv, byte[] tmpAesKey, byte[] data) {
    try {//from  w w  w.  jav  a  2 s .  c  om

        ByteBuffer out = ByteBuffer.allocate(data.length);

        byte[] iv2p = Arrays.copyOfRange(tmpAESiv, 0, tmpAESiv.length / 2);
        byte[] ivp = Arrays.copyOfRange(tmpAESiv, tmpAESiv.length / 2, tmpAESiv.length);

        int len = data.length / AES_BLOCK_SIZE;

        byte[] xorInput = null;
        byte[] xorOutput = null;

        SecretKeySpec keySpec = null;
        keySpec = new SecretKeySpec(tmpAesKey, "AES");
        Cipher cipher = null;
        cipher = Cipher.getInstance("AES/ECB/NoPadding");
        cipher.init(Cipher.DECRYPT_MODE, keySpec);

        byte[] input = null;
        byte[] output = null;

        for (int i = 0; i < len; i++) {
            input = Arrays.copyOfRange(data, i * AES_BLOCK_SIZE, (i + 1) * AES_BLOCK_SIZE);
            xorInput = xor(input, ivp);
            output = cipher.doFinal(xorInput);
            xorOutput = xor(output, iv2p);
            out.put(xorOutput);

            ivp = xorOutput;
            iv2p = input;
        }
        return out.array();
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (NoSuchPaddingException e) {
        e.printStackTrace();
    } catch (IllegalBlockSizeException e) {
        e.printStackTrace();
    } catch (BadPaddingException e) {
        e.printStackTrace();
    } catch (InvalidKeyException e) {
        e.printStackTrace();
    }

    return null;
}

From source file:Main.java

private static String generateSHA256(String offThis) {
    String result = "";
    try {/*from w w w.  java  2s.c  o m*/
        MessageDigest md = MessageDigest.getInstance("SHA-256");
        md.update(offThis.getBytes());
        byte mdBytes[] = md.digest();
        result = bytesToHex(mdBytes);
    } catch (NoSuchAlgorithmException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return result;
}