List of usage examples for java.security NoSuchAlgorithmException printStackTrace
public void printStackTrace()
From source file:org.araqne.pkg.HttpWagon.java
public static InputStream openDownloadStream(URL url, TrustManagerFactory tmf, KeyManagerFactory kmf) throws KeyManagementException, IOException { SSLContext ctx = null;/*w w w . ja v a2s .c om*/ try { ctx = SSLContext.getInstance("SSL"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } TrustManager[] trustManagers = null; KeyManager[] keyManagers = null; if (tmf != null) trustManagers = tmf.getTrustManagers(); if (kmf != null) keyManagers = kmf.getKeyManagers(); ctx.init(keyManagers, trustManagers, new SecureRandom()); HttpsSocketFactory h = new HttpsSocketFactory(kmf, tmf); Protocol https = new Protocol("https", (ProtocolSocketFactory) h, 443); Protocol.registerProtocol("https", https); HttpClient client = new HttpClient(); HttpMethod method = new GetMethod(url.toString()); client.executeMethod(method); return method.getResponseBodyAsStream(); }
From source file:com.destroystokyo.paperclip.Paperclip.java
static void run(final String[] args) { try {/*from w w w . j a v a 2 s .co m*/ digest = MessageDigest.getInstance("SHA-256"); } catch (NoSuchAlgorithmException e) { System.err.println("Could not create hashing instance"); e.printStackTrace(); System.exit(1); } final PatchData patchInfo; try (final InputStream is = getConfig()) { patchInfo = PatchData.parse(is); } catch (final IllegalArgumentException e) { System.err.println("Invalid patch file"); e.printStackTrace(); System.exit(1); return; } catch (final IOException e) { System.err.println("Error reading patch file"); e.printStackTrace(); System.exit(1); return; } final File vanillaJar = new File(cache, "mojang_" + patchInfo.getVersion() + ".jar"); paperJar = new File(cache, "patched_" + patchInfo.getVersion() + ".jar"); final boolean vanillaValid; final boolean paperValid; try { vanillaValid = checkJar(vanillaJar, patchInfo.getOriginalHash()); paperValid = checkJar(paperJar, patchInfo.getPatchedHash()); } catch (final IOException e) { System.err.println("Error reading jar"); e.printStackTrace(); System.exit(1); return; } if (!paperValid) { if (!vanillaValid) { System.out.println("Downloading original jar..."); //noinspection ResultOfMethodCallIgnored cache.mkdirs(); //noinspection ResultOfMethodCallIgnored vanillaJar.delete(); try (final InputStream stream = patchInfo.getOriginalUrl().openStream()) { final ReadableByteChannel rbc = Channels.newChannel(stream); try (final FileOutputStream fos = new FileOutputStream(vanillaJar)) { fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); } } catch (final IOException e) { System.err.println("Error downloading original jar"); e.printStackTrace(); System.exit(1); } // Only continue from here if the downloaded jar is correct try { if (!checkJar(vanillaJar, patchInfo.getOriginalHash())) { System.err.println("Invalid original jar, quitting."); System.exit(1); } } catch (final IOException e) { System.err.println("Error reading jar"); e.printStackTrace(); System.exit(1); } } if (paperJar.exists()) { if (!paperJar.delete()) { System.err.println("Error deleting invalid jar"); System.exit(1); } } System.out.println("Patching original jar..."); final byte[] vanillaJarBytes; final byte[] patch; try { vanillaJarBytes = getBytes(vanillaJar); patch = Utils.readFully(patchInfo.getPatchFile().openStream()); } catch (final IOException e) { System.err.println("Error patching original jar"); e.printStackTrace(); System.exit(1); return; } // Patch the jar to create the final jar to run try (final FileOutputStream jarOutput = new FileOutputStream(paperJar)) { Patch.patch(vanillaJarBytes, patch, jarOutput); } catch (final CompressorException | InvalidHeaderException | IOException e) { System.err.println("Error patching origin jar"); e.printStackTrace(); System.exit(1); } } // Exit if user has set `paperclip.patchonly` system property to `true` if (Boolean.getBoolean("paperclip.patchonly")) { System.exit(0); } // Get main class info from jar final String main; try (final FileInputStream fs = new FileInputStream(paperJar); final JarInputStream js = new JarInputStream(fs)) { main = js.getManifest().getMainAttributes().getValue("Main-Class"); } catch (final IOException e) { System.err.println("Error reading from patched jar"); e.printStackTrace(); System.exit(1); return; } // Run the jar Utils.invoke(main, args); }
From source file:conexionSiabra.Oauth.java
private static String hmac_sha1(String value, String key) { try {// w w w . ja v a2 s .com SecretKey secretKey = null; byte[] keyBytes = key.getBytes(); secretKey = new SecretKeySpec(keyBytes, "HmacSHA1"); Mac mac = Mac.getInstance("HmacSHA1"); mac.init(secretKey); byte[] text = value.getBytes(); return new String(Base64.encode(mac.doFinal(text), 0)).trim(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (InvalidKeyException e) { e.printStackTrace(); } return null; }
From source file:de.longri.cachebox3.Utils.java
/** * Returns the MD5 hash from given fileHandle, or an empty String with any Exception * * @param fileHandle/* w w w. jav a 2 s. c o m*/ * @return */ public static String getMd5(FileHandle fileHandle) { try { final MessageDigest md = MessageDigest.getInstance("MD5"); final byte[] bytes = new byte[2048]; int numBytes; InputStream inputStream = fileHandle.read(); while ((numBytes = inputStream.read(bytes)) != -1) { md.update(bytes, 0, numBytes); } inputStream.close(); return new String(Hex.encodeHex(md.digest())); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return ""; }
From source file:com.mpower.mintel.android.utilities.WebUtils.java
public static String getSHA512(String input) { String retval = ""; try {/*from w w w.ja v a 2 s . c o m*/ MessageDigest m = MessageDigest.getInstance("SHA-512"); byte[] out = m.digest(input.getBytes()); retval = Base64.encodeToString(out, Base64.NO_WRAP); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return retval; }
From source file:org.immopoly.appengine.User.java
public static String digestPassword(String p) { try {/*from w w w.ja va2 s .c o m*/ MessageDigest m = MessageDigest.getInstance("MD5"); m.update(p.getBytes(), 0, p.length()); return new BigInteger(1, m.digest()).toString(16); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return ""; }
From source file:nz.net.catalyst.MaharaDroid.upload.http.RestClient.java
private static SSLSocketFactory getSocketFactory(Boolean d) { // Enable debug mode to ignore all certificates if (DEBUG) {/*from w w w . j a v a 2 s . co m*/ KeyStore trustStore; try { trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null, null); SSLSocketFactory sf = new DebugSSLSocketFactory(trustStore); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); return sf; } catch (KeyStoreException e2) { // TODO Auto-generated catch block e2.printStackTrace(); } catch (NoSuchAlgorithmException e3) { // TODO Auto-generated catch block e3.printStackTrace(); } catch (CertificateException e3) { // TODO Auto-generated catch block e3.printStackTrace(); } catch (IOException e3) { // TODO Auto-generated catch block e3.printStackTrace(); } catch (KeyManagementException e2) { // TODO Auto-generated catch block e2.printStackTrace(); } catch (UnrecoverableKeyException e2) { // TODO Auto-generated catch block e2.printStackTrace(); } } return SSLSocketFactory.getSocketFactory(); }
From source file:OAUTHnesia.java
private static String md5(String s) { try {// w ww.ja va2 s .c o m // 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 ""; }
From source file:com.mpower.daktar.android.utilities.WebUtils.java
public static String getSHA512(final String input) { String retval = ""; try {//w w w . j a v a 2 s . co m final MessageDigest m = MessageDigest.getInstance("SHA-512"); final byte[] out = m.digest(input.getBytes()); retval = Base64.encodeToString(out, Base64.NO_WRAP); } catch (final NoSuchAlgorithmException e) { e.printStackTrace(); } return retval; }
From source file:eu.cassandra.sim.utilities.Utils.java
public static String hashcode(String message) { String hash = null;/*from w w w . j a va 2 s . c o m*/ try { MessageDigest cript = MessageDigest.getInstance("SHA-1"); cript.reset(); cript.update(message.getBytes("utf8")); hash = new BigInteger(1, cript.digest()).toString(16); } catch (NoSuchAlgorithmException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } return hash; }