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.umit.icm.mobile.process.KeyManager.java

/**
 * Writes the PrivateKey to disk.//from  w ww .  ja  v a  2 s. c o m
 *
 *
         
 @param myPrivateKey PrivateKey of type {@link PrivateKey}
 *
         
 @see CryptoKeyWriter
 */
public synchronized void setMyPrivateKey(PrivateKey myPrivateKey) {
    this.myPrivateKey = myPrivateKey;
    try {
        CryptoKeyWriter.writeMyPrivateKey(this.myPrivateKey);
    } catch (NoSuchAlgorithmException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InvalidKeySpecException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:org.umit.icm.mobile.process.KeyManager.java

/**
 * Writes the PublicKey to disk.//  ww w  .  ja  v  a 2s  .c  o m
 *
 *
         
 @param myPublicKey PublicKey of type {@link PublicKey}
 *
         
 @see CryptoKeyWriter
 */
public synchronized void setMyPublicKey(PublicKey myPublicKey) {
    this.myPublicKey = myPublicKey;
    try {
        CryptoKeyWriter.writeMyPublicKey(this.myPublicKey);
    } catch (NoSuchAlgorithmException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InvalidKeySpecException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:org.mitre.jwt.signer.service.impl.DefaultJwtSigningAndValidationService.java

@Override
public boolean validateSignature(String jwtString) {

    for (JwtSigner signer : getSigners().values()) {
        try {/*from  www. ja v a  2  s .co m*/
            if (signer.verify(jwtString)) {
                return true;
            }
        } catch (NoSuchAlgorithmException e) {
            // ignore, signer didn't verify signature, try the next one
            e.printStackTrace();
        }
    }
    return false;
}

From source file:com.atlassian.theplugin.commons.ssl.PluginSSLProtocolSocketFactory.java

private PluginSSLProtocolSocketFactory() {
    try {/*from  w  ww  . j a v  a2 s  . c o  m*/
        trustManager = new ConnectorTrustManager(PluginSSLProtocolSocketFactory.generalConfigurationBean,
                PluginSSLProtocolSocketFactory.certMessageDialog, getKeyStore());

    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (KeyStoreException e) {
        e.printStackTrace();
    }
}

From source file:edu.csueb.cs6320.utils.UserService.java

public boolean updatePassword(long userid, String newPassword) {
    EntityManager em = Persistence.createEntityManagerFactory("TestPU").createEntityManager();
    User u = em.find(User.class, userid);
    if (u == null) {
        return false;
    }//  www .j  av  a2 s  .  com

    em.getTransaction().begin();

    // TODO: This block of code really belongs in User.setPassword()
    String salt = Auth.getSalt();
    u.setSalt(salt);
    try {
        u.setSaltedHashedPassword(Auth.hashPassword(newPassword, salt));
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
        em.getTransaction().rollback();
        return false;
    }
    em.getTransaction().commit();
    em.close();

    return true;
}

From source file:com.hkm.Application.appWork.java

private String sha1Hash(String toHash) {
    String hash = null;//from ww  w  . j  a v a 2s.com
    try {
        MessageDigest digest = MessageDigest.getInstance("SHA-1");
        byte[] bytes = toHash.getBytes("UTF-8");
        digest.update(bytes, 0, bytes.length);
        bytes = digest.digest();

        // This is ~55x faster than looping and String.formating()
        hash = bytesToHex(bytes);
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return hash;
}

From source file:dz.alkhwarizmix.framework.java.utils.CryptoUtil.java

/**
 * Constructor./*w  w  w.j a v  a2  s .c o  m*/
 */
public CryptoUtil(String pKey, String pEncType, String pModeType, boolean pSimple, String pPaddingType) {

    if (pEncType == null)
        pEncType = "aes";
    pEncType = pEncType.toUpperCase();

    if (pModeType == null)
        pModeType = "cbc"; // ecb, cbc, ofb
    pModeType = pModeType.toUpperCase();

    if (pPaddingType == null)
        pPaddingType = "pkcs5";

    String pHexKey = stringToHex(pKey);
    pHexKey = pHexKey.substring(0, 64);
    String pHexIV = pHexKey.substring(0, 32);

    byte[] kdata = hex2Byte(pHexKey);
    String pad = ((pPaddingType == "pkcs5") ? "PKCS5" : "No") + "Padding";
    String algo = pEncType + "/" + pModeType + "/" + pad;
    secretKeySpec = new SecretKeySpec(kdata, pEncType);
    ivParameterSpec = new IvParameterSpec(hex2Byte(pHexIV));
    try {
        cipher = Cipher.getInstance(algo);
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (NoSuchPaddingException e) {
        e.printStackTrace();
    }
}

From source file:org.globusonline.nexus.GlobusOnlineRestClient.java

private long generateNonce() {
    SecureRandom sr = null;/*from  w  ww .ja  va 2 s .c  o  m*/
    try {
        sr = SecureRandom.getInstance("SHA1PRNG");
        byte[] bytes = new byte[1024 / 8];
        sr.nextBytes(bytes);
        int seedByteCount = 10;
        byte[] seed = sr.generateSeed(seedByteCount);
        sr = SecureRandom.getInstance("SHA1PRNG");
        sr.setSeed(seed);
    } catch (NoSuchAlgorithmException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return sr.nextLong();
}

From source file:ch.icclab.cyclops.client.CloudStackAuth.java

/**
 * Perform construction of URL based on command provided, with some parameters as hashmap(key, value)
 *
 * @return constructed URL string/*w w w  .  j  a va  2 s .c  o m*/
 */
private String constructURL() {
    logger.trace("Constructing CloudStack API URL");

    // construct standard header
    Map<String, String> header = constructHeader();

    // now create url
    String queryString = Joiner.on("&").withKeyValueSeparator("=").join(header);

    try {
        // sign the normalised query string
        String signature = signRequest(queryString.toLowerCase());

        // add signature to our query string
        queryString = queryString.concat("&signature=".concat(signature));

        // return signed string
        return apiConnection.getCloudStackURL().concat("?".concat(queryString));

    } catch (NoSuchAlgorithmException e) {
        logger.error("Couldn't find encryption algorithm for signing CloudStack API URL");
        e.printStackTrace();
    } catch (InvalidKeyException e) {
        logger.error("Invalid Secret Key provided when trying to sign CloudStack API URL");
        e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
        logger.error("Unsupported Encoding used when trying to sign CloudStack API URL");
        e.printStackTrace();
    }

    // return empty string if something went wrong
    return "";
}

From source file:net.networksaremadeofstring.rhybudd.ZenossAPI.java

public static String md5(String s) {
    try {/*from  w  ww.  j  a  va2  s .  c om*/
        // 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++)
            hexString.append(Integer.toHexString(0xFF & messageDigest[i]));
        return hexString.toString();

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