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;
}
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);
}
}
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));
}
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);
}
}
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;
}
Aggregations