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:eu.planets_project.pp.plato.application.AdminAction.java

private static String computeSHA(String input) {
    try {/*w w  w  .  java  2s  . c o m*/
        MessageDigest md = MessageDigest.getInstance("SHA-1");
        md.update(input.getBytes("UTF-8"));
        byte[] code = md.digest();
        return convertToHex(code);
    } catch (NoSuchAlgorithmException e) {
        log.error("Algorithm SHA-1 not found!", e);
        e.printStackTrace();
        return null;
    } catch (UnsupportedEncodingException e) {
        log.error("Encoding problem: UTF-8 not supported!", e);
        e.printStackTrace();
        return null;
    }
}

From source file:io.coldstart.android.API.java

public static String md5(String s) {
    /*try/* w w  w .j a  va  2 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 "";*/

    MessageDigest mdEnc = null;
    try {
        mdEnc = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException e) {
        Log.e("Exception", "Exception while encrypting to md5");
        e.printStackTrace();
    }

    mdEnc.update(s.getBytes(), 0, s.length());
    String md5 = new BigInteger(1, mdEnc.digest()).toString(16);
    return md5;
}

From source file:finale.year.stage.utility.Util.java

public static JSONObject login(String email, String password) {
    HttpJSONExchange exchange = new HttpJSONExchange();

    HashMap<String, String> headers = new HashMap<String, String>();
    HashMap<String, String> params = new HashMap<String, String>();
    //Path  of Server on Machine
    //String url = LOCAL+"login"; 
    String url = ROOT + "login";

    headers.put("User-Agent", "desktop");
    params.put("email", email);
    try {//from   w ww .  j  a  v  a  2  s  .c  om
        if (CHECK == false) //Not Encrypted of Existing config.txt with Pass
            params.put("password", encryptPassword(password));
        else
            params.put("password", password);

    } catch (NoSuchAlgorithmException ex) {
        ex.printStackTrace();
    }
    //Handle Unknown Host
    JSONObject json = null;

    if (isAv(mainF.mainFrame)) //Check Internet Connection 
        json = exchange.sendPOSTRequest(url, params, headers);

    //Return Result to LoginWindow
    return json;
}

From source file:me.disconnect.mobile.billing.Security.java

/**
 * Verifies that the signature from the server matches the computed
 * signature on the data.  Returns true if the data is correctly signed.
 *
 * @param publicKey public key associated with the developer account
 * @param signedData signed data from server
 * @param signature server signature/* w  w w.j  a v a  2  s. com*/
 * @return true if the data and signature match
 */
public static boolean verify(PublicKey publicKey, String signedData, String signature) {
    Signature sig;
    try {
        sig = Signature.getInstance(SIGNATURE_ALGORITHM);
        sig.initVerify(publicKey);
        sig.update(signedData.getBytes());
        if (!sig.verify(Base64.decode(signature))) {
            Log.e(TAG, "Signature verification failed.");
            return false;
        }
        return true;
    } catch (NoSuchAlgorithmException e) {
        Log.e(TAG, "NoSuchAlgorithmException.");
    } catch (InvalidKeyException e) {
        Log.e(TAG, "Invalid key specification.");
    } catch (SignatureException e) {
        Log.e(TAG, "Signature exception.");
    } catch (Base64DecoderException e) {
        Log.e(TAG, "Base64 decoding failed.");
    } catch (RuntimeException e) {
        Log.e(TAG, "RuntimeException in Security.verify():");
        e.printStackTrace();
    }
    return false;
}

From source file:org.opendatakit.persistence.table.RegisteredUsersTable.java

private static final boolean resetSuperUserPasswordIfNecessary(RegisteredUsersTable registeredUsersTable,
        boolean newUser,
        // MessageDigestPasswordEncoder digester,
        CallingContext callingContext)/*from   ww w .j  av  a2 s  . co m*/
        throws ODKEntityPersistException, ODKOverQuotaException, ODKEntityNotFoundException {
    String localSuperUser = registeredUsersTable.getUsername();
    String currentRealmString = callingContext.getUserService().getCurrentRealm().getRealmString();
    String lastKnownRealmString = ServerPreferencesPropertiesTable.getLastKnownRealmString(callingContext);
    if (!newUser && lastKnownRealmString != null && lastKnownRealmString.equals(currentRealmString)) {
        // no need to reset the passwords
        return false;
    }
    // The realm string has changed, so we need to reset the password.
    RealmSecurityInfo realmSecurityInfo = new RealmSecurityInfo();
    realmSecurityInfo.setRealmString(currentRealmString);
    // realmSecurityInfo.setBasicAuthHashEncoding(digester.getAlgorithm());

    CredentialsInfo credential;
    try {
        credential = CredentialsInfoBuilder.build(localSuperUser, realmSecurityInfo, "aggregate");
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
        throw new IllegalStateException("unrecognized algorithm");
    }
    registeredUsersTable.setDigestAuthPassword(credential.getDigestAuthHash());
    registeredUsersTable.setBasicAuthPassword(credential.getBasicAuthHash());
    registeredUsersTable.setBasicAuthSalt(credential.getBasicAuthSalt());
    // done setting the password...persist it...
    registeredUsersTable.setIsRemoved(false);
    callingContext.getDatastore().putEntity(registeredUsersTable, callingContext.getCurrentUser());
    // remember the current realm string
    ServerPreferencesPropertiesTable.setLastKnownRealmString(callingContext, currentRealmString);
    logger.warn("Reset password of the local superuser record: " + registeredUsersTable.getUri()
            + " identified by: " + registeredUsersTable.getUsername());
    return true;
}

From source file:de.unidue.stud.sehawagn.oidcclient.SimpleOIDCClient.java

private static SSLContext getTrustEverybodySSLContext() {
    // Create a trust manager that does not validate certificate chains
    TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
        public java.security.cert.X509Certificate[] getAcceptedIssuers() {
            return null;
        }// w w  w.j  a  v a2s  . c  o m

        public void checkClientTrusted(X509Certificate[] certs, String authType) {
        }

        public void checkServerTrusted(X509Certificate[] certs, String authType) {
        }
    } };

    SSLContext sc = null;
    try {
        sc = SSLContext.getInstance("SSL");
        sc.init(null, trustAllCerts, new java.security.SecureRandom());
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (KeyManagementException e) {
        e.printStackTrace();
    }
    return sc;
}

From source file:org.opendatakit.common.security.spring.RegisteredUsersTable.java

private static final boolean resetSuperUserPasswordIfNecessary(RegisteredUsersTable t, boolean newUser,
        MessageDigestPasswordEncoder mde, CallingContext cc)
        throws ODKEntityPersistException, ODKOverQuotaException, ODKEntityNotFoundException {
    String localSuperUser = t.getUsername();
    String currentRealmString = cc.getUserService().getCurrentRealm().getRealmString();
    String lastKnownRealmString = ServerPreferencesProperties.getLastKnownRealmString(cc);
    if (!newUser && lastKnownRealmString != null && lastKnownRealmString.equals(currentRealmString)) {
        // no need to reset the passwords
        return false;
    }//from   w  w w  . j a v a 2 s.  c  o m
    // The realm string has changed, so we need to reset the password.
    RealmSecurityInfo r = new RealmSecurityInfo();
    r.setRealmString(currentRealmString);
    r.setBasicAuthHashEncoding(mde.getAlgorithm());

    CredentialsInfo credential;
    try {
        credential = CredentialsInfoBuilder.build(localSuperUser, r, "aggregate");
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
        throw new IllegalStateException("unrecognized algorithm");
    }
    t.setDigestAuthPassword(credential.getDigestAuthHash());
    t.setBasicAuthPassword(credential.getBasicAuthHash());
    t.setBasicAuthSalt(credential.getBasicAuthSalt());
    // done setting the password...persist it...
    t.setIsRemoved(false);
    cc.getDatastore().putEntity(t, cc.getCurrentUser());
    // remember the current realm string
    ServerPreferencesProperties.setLastKnownRealmString(cc, currentRealmString);
    logger.warn("Reset password of the local superuser record: " + t.getUri() + " identified by: "
            + t.getUsername());
    return true;
}

From source file:org.dasein.cloud.terremark.Terremark.java

private static String sign(byte[] key, String authString, String algorithm) throws InternalException {
    try {// ww w .  j a  va  2s.  co  m
        Mac mac = Mac.getInstance(algorithm);

        mac.init(new SecretKeySpec(key, algorithm));
        return new String(Base64.encodeBase64(mac.doFinal(authString.getBytes("utf-8"))));
    } catch (NoSuchAlgorithmException e) {
        logger.error(e);
        e.printStackTrace();
        throw new InternalException(e);
    } catch (InvalidKeyException e) {
        logger.error(e);
        e.printStackTrace();
        throw new InternalException(e);
    } catch (IllegalStateException e) {
        logger.error(e);
        e.printStackTrace();
        throw new InternalException(e);
    } catch (UnsupportedEncodingException e) {
        logger.error(e);
        e.printStackTrace();
        throw new InternalException(e);
    }
}

From source file:org.gdg.frisbee.android.cache.ModelCache.java

private static String transformUrlForDiskCacheKey(String url) {
    try {/*from w ww.  j ava 2s  . com*/
        // Create MD5 Hash
        MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
        digest.update(url.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 "";
}

From source file:de.madvertise.android.sdk.MadvertiseUtil.java

/**
 * Returns the MD5 hash for a string.// w ww  . j  a v a 2 s . com
 * 
 * @param input
 * @return md5 hash
 */
public synchronized static String getHash(final String input, HashType hashType) {
    MessageDigest messageDigest = null;

    try {
        messageDigest = MessageDigest.getInstance(hashType.toString());
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
        MadvertiseUtil.logMessage(null, Log.DEBUG, "Could not create hash value");
        return "";
    }
    messageDigest.update(input.getBytes());
    String temp = null;
    byte[] digest = messageDigest.digest();
    StringBuffer hexString = new StringBuffer();
    for (int i = 0; i < digest.length; i++) {
        temp = Integer.toHexString(0xFF & digest[i]);
        if (temp.length() < 2) {
            temp = "0" + temp;
        }
        hexString.append(temp);
    }

    return hexString.toString();
}