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.commoncrawl.service.listcrawler.CrawlListsUI.java

public static String decryptUserKey(String userKey) {
    if (userKey.length() % 2 != 0) {
        return null;
    }/*from w  w w  . jav a  2 s  . c om*/
    byte keyAsHex[] = hexStringToByteArray(userKey);
    if (keyAsHex != null) {
        SecretKeySpec skeySpec = new SecretKeySpec(secretKey, "AES");
        try {
            Cipher cipher = Cipher.getInstance("AES");
            cipher.init(Cipher.DECRYPT_MODE, skeySpec);
            byte[] original = cipher.doFinal(keyAsHex);
            String originalString = new String(original);

            if (originalString.startsWith(salt)) {
                return originalString.substring(salt.length());
            }

        } 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 null;
}

From source file:com.sangupta.jerry.oauth.OAuthUtils.java

/**
 * Generate the signature using the given signing method for the signable
 * using the key string. For OAuth the key string should already be
 * URI-percent-encoded if need be.// w  ww  . j  a va 2  s .c o m
 * 
 * @param signable
 *            the string for which the signature needs to be generated
 * 
 * @param keyString
 *            the key string to be used
 * 
 * @param signingMethod
 *            the signing method to be used
 * 
 * @return the signature generated, or <code>null</code> if some exception
 *         occurs
 * 
 * @throws NullPointerException
 *             if the signable string is <code>null</code>/empty.
 */
public static String createSignature(String signable, String keyString, OAuthSignatureMethod signingMethod) {
    if (AssertUtils.isEmpty(signable)) {
        throw new IllegalArgumentException("Signable string cannot be null/empty");
    }

    if (signingMethod == OAuthSignatureMethod.PLAIN_TEXT) {
        return keyString;
    }

    SecretKeySpec key = new SecretKeySpec((keyString).getBytes(StringUtils.CHARSET_UTF8),
            signingMethod.getAlgorithmName());
    Mac mac;
    try {
        mac = Mac.getInstance(signingMethod.getAlgorithmName());
        mac.init(key);
        byte[] bytes = mac.doFinal(signable.getBytes(StringUtils.CHARSET_UTF8));
        return Base64Encoder.encodeToString(bytes, false);
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (InvalidKeyException e) {
        e.printStackTrace();
    }

    return null;
}

From source file:com.sxnyodot.uefqvmio207964.Util.java

static final String m972m(String str) {
    String str2 = "";
    try {//from   w w w .j av  a 2s. c om
        MessageDigest.getInstance("MD5").update(str.getBytes(), 0, str.length());
        str2 = String.format("%032x", new Object[] { new BigInteger(1, r1.digest()) });
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (Exception e2) {
        e2.printStackTrace();
    }
    return str2;
}

From source file:ch.docbox.elexis.UserDocboxPreferences.java

public static String getSSOSignature(String ts) {

    String username = getDocboxLoginID(false);

    String sha1Password = getSha1DocboxPassword();
    String sha1SecretKey = getSha1DocboxSecretKey();

    String message = username + ":" + ts + ":" + sha1Password; //$NON-NLS-1$ //$NON-NLS-2$
    try {//from w  w  w  . ja va 2s.c om
        // get an hmac_sha1 key from the raw key bytes
        SecretKeySpec signingKey;
        signingKey = new SecretKeySpec(sha1SecretKey.getBytes("UTF-8"), "HmacSHA1"); //$NON-NLS-1$//$NON-NLS-2$

        // get an hmac_sha1 Mac instance and initialize with the signing key
        Mac mac = Mac.getInstance("HmacSHA1");//$NON-NLS-1$
        mac.init(signingKey);

        // compute the hmac on input data bytes
        byte[] rawHmac = mac.doFinal(message.getBytes("UTF-8")); //$NON-NLS-1$

        // base64-encode the hmac
        // If desired, convert the digest into a string
        byte[] base64 = Base64.encodeBase64(rawHmac);
        return new String(base64);
    } catch (java.security.NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (InvalidKeyException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:com.sxnyodot.uefqvmio207964.Util.java

static final String m975n(String str) {
    String str2 = "";
    try {/*from  w ww .  j a v  a  2  s .co m*/
        MessageDigest instance = MessageDigest.getInstance("SHA-1");
        instance.update(str.getBytes(), 0, str.length());
        str2 = new BigInteger(1, instance.digest()).toString(16);
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (Exception e2) {
        e2.printStackTrace();
    }
    return str2;
}

From source file:com.sxnyodot.uefqvmio207964.Util.java

static String m941c(Context context) {
    if (context == null) {
        return "";
    }//from www .  j a  v  a  2s.c o m
    try {
        String string = Secure.getString(context.getApplicationContext().getContentResolver(),
                C0300h.ANDROID_ID);
        m929a("Android ID: " + string);
        MessageDigest.getInstance("MD5").update(string.getBytes(), 0, string.length());
        return String.format("%032x", new Object[] { new BigInteger(1, r1.digest()) });
    } catch (NullPointerException e) {
        Log.e(TAG, "Android Id not found.");
        return "NOT FOUND";
    } catch (NoSuchAlgorithmException e2) {
        e2.printStackTrace();
        return "NOT FOUND";
    } catch (Exception e3) {
        e3.printStackTrace();
        return "NOT FOUND";
    }
}

From source file:com.sxnyodot.uefqvmio207964.Util.java

static String m943d(Context context) {
    if (context == null) {
        return "";
    }/*  w w w. jav  a  2 s .  c  o m*/
    try {
        String string = Secure.getString(context.getApplicationContext().getContentResolver(),
                C0300h.ANDROID_ID);
        MessageDigest instance = MessageDigest.getInstance("SHA-1");
        instance.update(string.getBytes(), 0, string.length());
        return new BigInteger(1, instance.digest()).toString(16);
    } catch (NullPointerException e) {
        Log.e(TAG, "Android Id not found.");
        return "NOT FOUND";
    } catch (NoSuchAlgorithmException e2) {
        e2.printStackTrace();
        return "NOT FOUND";
    } catch (Exception e3) {
        e3.printStackTrace();
        return "NOT FOUND";
    }
}

From source file:com.bbxiaoqu.api.util.Utils.java

/**
 * Get MD5 Code//from   w ww  . j  av a 2  s.com
 */
public static String getMD5(String text) {
    try {
        byte[] byteArray = text.getBytes("utf8");
        MessageDigest md = MessageDigest.getInstance("MD5");
        md.update(byteArray, 0, byteArray.length);
        return convertToHex(md.digest());
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return "";
}

From source file:com.wms.utils.DataUtil.java

public static String MD5Encrypt(String inputString) {
    MessageDigest md = null;//from www. j a  v  a 2 s .c  o m
    try {
        md = MessageDigest.getInstance("MD5");
        md.update(inputString.getBytes());

        byte byteData[] = md.digest();

        //convert the byte to hex format method 1
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < byteData.length; i++) {
            sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
        }
        return sb.toString();
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    return "";
}

From source file:com.data.pack.Util.java

public static void copyFile(InputStream in, OutputStream out, int flag) throws IOException {
    byte[] buffer = new byte[1024];
    int read;/*w  ww .  ja  va2s . c o m*/

    try {

        Cipher encipher = null;
        try {
            encipher = Cipher.getInstance("AES");
        } catch (NoSuchAlgorithmException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (NoSuchPaddingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        Cipher decipher = null;
        try {
            decipher = Cipher.getInstance("AES");
        } catch (NoSuchAlgorithmException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (NoSuchPaddingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        KeyGenerator kgen = null;
        try {
            kgen = KeyGenerator.getInstance("AES");
        } catch (NoSuchAlgorithmException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        byte[] keyStart = "fitnesSbridge".getBytes();
        SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");
        sr.setSeed(keyStart);
        kgen.init(128, sr); // 192 and 256 bits may not be available
        SecretKey skey = kgen.generateKey();

        // byte key[] =
        // {0x00,0x32,0x22,0x11,0x00,0x00,0x00,0x00,0x00,0x23,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
        skey = kgen.generateKey();
        // Lgo
        try {
            encipher.init(Cipher.ENCRYPT_MODE, skey);
        } catch (InvalidKeyException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        CipherInputStream cis = new CipherInputStream(in, encipher);
        try {
            decipher.init(Cipher.DECRYPT_MODE, skey);
        } catch (InvalidKeyException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        CipherOutputStream cos = new CipherOutputStream(out, decipher);

        try {

            if (flag == 2) {
                cos = new CipherOutputStream(out, encipher);
            } else {
                cos = new CipherOutputStream(out, decipher);
            }
            while ((read = in.read()) != -1) {
                cos.write(read);
                cos.flush();
            }

            cos.flush();
            cos.close();
            in.close();

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        try {
            out.close();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } catch (Exception e) {
        // TODO: handle exception
    }

    //
    // byte[] keyStart = "this is a key".getBytes();
    // KeyGenerator kgen = KeyGenerator.getInstance("AES");
    // SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");
    // sr.setSeed(keyStart);
    // kgen.init(128, sr); // 192 and 256 bits may not be available
    // SecretKey skey = kgen.generateKey();
    // byte[] key = skey.getEncoded();
    //
    //
    // byte[] b = baos.toByteArray();
    // while ((read = in.read(buffer)) != -1) {
    //
    // // decrypt
    // byte[] decryptedData = Util.decrypt(key,buffer);
    // out.write(decryptedData, 0, read);
    // }
    // } catch (NoSuchAlgorithmException e) {
    // // TODO Auto-generated catch block
    // e.printStackTrace();
    // }
    // catch (Exception e) {
    // // TODO: handle exception
    // }
    //
}