Search in sources :

Example 26 with NoSuchAlgorithmException

use of java.security.NoSuchAlgorithmException in project hackpad by dropbox.

the class Main method getDigest.

private static byte[] getDigest(Object source) {
    byte[] bytes, digest = null;
    if (source != null) {
        if (source instanceof String) {
            try {
                bytes = ((String) source).getBytes("UTF-8");
            } catch (UnsupportedEncodingException ue) {
                bytes = ((String) source).getBytes();
            }
        } else {
            bytes = (byte[]) source;
        }
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            digest = md.digest(bytes);
        } catch (NoSuchAlgorithmException nsa) {
            // Should not happen
            throw new RuntimeException(nsa);
        }
    }
    return digest;
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MessageDigest(java.security.MessageDigest)

Example 27 with NoSuchAlgorithmException

use of java.security.NoSuchAlgorithmException in project che by eclipse.

the class PBKDF2PasswordEncryptor method computeHash.

private HashCode computeHash(char[] password, byte[] salt, int iterations) {
    try {
        final SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(SECRET_KEY_FACTORY_NAME);
        final KeySpec keySpec = new PBEKeySpec(password, salt, iterations, 512);
        return HashCode.fromBytes(keyFactory.generateSecret(keySpec).getEncoded());
    } catch (NoSuchAlgorithmException | InvalidKeySpecException x) {
        throw new RuntimeException(x.getMessage(), x);
    }
}
Also used : PBEKeySpec(javax.crypto.spec.PBEKeySpec) KeySpec(java.security.spec.KeySpec) PBEKeySpec(javax.crypto.spec.PBEKeySpec) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) SecretKeyFactory(javax.crypto.SecretKeyFactory)

Example 28 with NoSuchAlgorithmException

use of java.security.NoSuchAlgorithmException in project hackpad by dropbox.

the class SASLXFacebookPlatformMechanism method challengeReceived.

@Override
public void challengeReceived(String challenge) throws IOException {
    byte[] response = null;
    if (challenge != null) {
        String decodedChallenge = new String(Base64.decode(challenge));
        Map<String, String> parameters = getQueryMap(decodedChallenge);
        String version = "1.0";
        String nonce = parameters.get("nonce");
        String method = parameters.get("method");
        long callId = new GregorianCalendar().getTimeInMillis();
        String sig = "api_key=" + apiKey + "call_id=" + callId + "method=" + method + "nonce=" + nonce + "access_token=" + sessionKey + "v=" + version;
        try {
            sig = md5(sig);
        } catch (NoSuchAlgorithmException e) {
            throw new IllegalStateException(e);
        }
        String composedResponse = "api_key=" + URLEncoder.encode(apiKey, "utf-8") + "&call_id=" + callId + "&method=" + URLEncoder.encode(method, "utf-8") + "&nonce=" + URLEncoder.encode(nonce, "utf-8") + "&access_token=" + URLEncoder.encode(sessionKey, "utf-8") + "&v=" + URLEncoder.encode(version, "utf-8") + "&sig=" + URLEncoder.encode(sig, "utf-8");
        response = composedResponse.getBytes("utf-8");
    }
    String authenticationText = "";
    if (response != null) {
        authenticationText = Base64.encodeBytes(response, Base64.DONT_BREAK_LINES);
    }
    // Send the authentication to the server
    getSASLAuthentication().send(new Response(authenticationText));
}
Also used : GregorianCalendar(java.util.GregorianCalendar) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 29 with NoSuchAlgorithmException

use of java.security.NoSuchAlgorithmException in project druid by druid-io.

the class JavaScriptAggregatorFactory method getCacheKey.

@Override
public byte[] getCacheKey() {
    try {
        MessageDigest md = MessageDigest.getInstance("SHA-1");
        byte[] fieldNameBytes = StringUtils.toUtf8(Joiner.on(",").join(fieldNames));
        byte[] sha1 = md.digest(StringUtils.toUtf8(fnAggregate + fnReset + fnCombine));
        return ByteBuffer.allocate(1 + fieldNameBytes.length + sha1.length).put(CACHE_TYPE_ID).put(fieldNameBytes).put(sha1).array();
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException("Unable to get SHA1 digest instance", e);
    }
}
Also used : NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MessageDigest(java.security.MessageDigest)

Example 30 with NoSuchAlgorithmException

use of java.security.NoSuchAlgorithmException in project AndroidNetworkDemo by dodocat.

the class RequestManager method newRequestQueue.

private RequestQueue newRequestQueue(Context context) {
    RequestQueue requestQueue;
    try {
        String[] hosts = { "kyfw.12306.cn" };
        int[] certRes = { R.raw.kyfw };
        String[] certPass = { "asdfqaz" };
        socketFactoryMap = new Hashtable<>(hosts.length);
        for (int i = 0; i < certRes.length; i++) {
            int res = certRes[i];
            String password = certPass[i];
            SSLSocketFactory sslSocketFactory = createSSLSocketFactory(context, res, password);
            socketFactoryMap.put(hosts[i], sslSocketFactory);
        }
        HurlStack stack = new SelfSignSslOkHttpStack(socketFactoryMap);
        requestQueue = Volley.newRequestQueue(context, stack);
        requestQueue.start();
    } catch (KeyStoreException | CertificateException | NoSuchAlgorithmException | KeyManagementException | IOException e) {
        throw new RuntimeException(e);
    }
    return requestQueue;
}
Also used : HurlStack(com.android.volley.toolbox.HurlStack) CertificateException(java.security.cert.CertificateException) KeyStoreException(java.security.KeyStoreException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) KeyManagementException(java.security.KeyManagementException) RequestQueue(com.android.volley.RequestQueue) SSLSocketFactory(javax.net.ssl.SSLSocketFactory)

Aggregations

NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1403 MessageDigest (java.security.MessageDigest)548 IOException (java.io.IOException)328 InvalidKeyException (java.security.InvalidKeyException)242 KeyStoreException (java.security.KeyStoreException)168 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)145 CertificateException (java.security.cert.CertificateException)138 UnsupportedEncodingException (java.io.UnsupportedEncodingException)131 KeyManagementException (java.security.KeyManagementException)105 KeyFactory (java.security.KeyFactory)96 NoSuchProviderException (java.security.NoSuchProviderException)93 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)89 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)79 UnrecoverableKeyException (java.security.UnrecoverableKeyException)78 KeyStore (java.security.KeyStore)73 SecureRandom (java.security.SecureRandom)72 SSLContext (javax.net.ssl.SSLContext)72 X509EncodedKeySpec (java.security.spec.X509EncodedKeySpec)69 BadPaddingException (javax.crypto.BadPaddingException)69 Cipher (javax.crypto.Cipher)69