List of usage examples for java.security NoSuchAlgorithmException printStackTrace
public void printStackTrace()
From source file:org.apache.catalina.realm.RealmBase.java
/** * Return the digest associated with given principal's user name. *///from w w w . jav a 2 s. c om protected String getDigest(String username, String realmName) { if (md5Helper == null) { try { md5Helper = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); throw new IllegalStateException(); } } String digestValue = username + ":" + realmName + ":" + getPassword(username); byte[] digest = md5Helper.digest(digestValue.getBytes()); return md5Encoder.encode(digest); }
From source file:io.pyd.synchro.SyncJob.java
public static String computeMD5(File f) { MessageDigest digest;//from w w w .j a va 2 s . c o m try { digest = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e1) { e1.printStackTrace(); return ""; } InputStream is; try { is = new FileInputStream(f); } catch (FileNotFoundException e1) { e1.printStackTrace(); return ""; } byte[] buffer = new byte[8192]; int read = 0; try { while ((read = is.read(buffer)) > 0) { digest.update(buffer, 0, read); } byte[] md5sum = digest.digest(); BigInteger bigInt = new BigInteger(1, md5sum); String output = bigInt.toString(16); if (output.length() < 32) { // PAD WITH 0 while (output.length() < 32) output = "0" + output; } return output; } catch (IOException e) { // throw new RuntimeException("Unable to process file for MD5", e); return ""; } finally { try { is.close(); } catch (IOException e) { // throw new // RuntimeException("Unable to close input stream for MD5 calculation", // e); return ""; } } }
From source file:com.miz.functions.MizLib.java
public static String md5(final String s) { try {/*from ww w . j a v a 2 s . com*/ // 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++) { String h = Integer.toHexString(0xFF & messageDigest[i]); while (h.length() < 2) h = "0" + h; hexString.append(h); } return hexString.toString(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return ""; }
From source file:com.mediatek.systemupdate.HttpManager.java
private String getToken() { Xlog.i(TAG, "getToken"); StringBuffer buf = new StringBuffer(); try {//www. j a v a2s .c om if (mCookies == null) { handsakeAuthentication(); } String strCookie = getRandCookieStr(); if (strCookie == null) { handsakeAuthentication(); } strCookie = getRandCookieStr(); if (strCookie == null) { Xlog.i(TAG, "could not get cookie value"); return null; } MessageDigest md5 = MessageDigest.getInstance("MD5"); md5.update(strCookie.getBytes()); byte[] bytes = md5.digest(); for (int i = 0; i < bytes.length; i++) { String s = Integer.toHexString(bytes[i] & UpgradePkgManager.MD5_MASK); if (s.length() == 1) { buf.append("0"); } buf.append(s); } } catch (NoSuchAlgorithmException e) { e.printStackTrace(); return null; } return buf.toString(); }
From source file:org.dasein.cloud.aws.AWSCloud.java
private String sign(byte[] key, String authString, String algorithm) throws InternalException { try {// ww w . j av a2s . 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:com.zoffcc.applications.aagtl.HTMLDownloader.java
public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException, UnknownHostException { SSLContext sslContext = null; try {/*from w ww.j ava 2 s. co m*/ sslContext = SSLContext.getInstance("TLS"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return sslContext.getSocketFactory().createSocket(socket, host, port, autoClose); }
From source file:com.jtschohl.androidfirewall.MainActivity.java
/** * Hash the password/*from w ww.j av a 2 s .c o m*/ */ public static final String md5(final String s) { try { // 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++) { String h = Integer.toHexString(0xFF & messageDigest[i]); while (h.length() < 2) h = "0" + h; hexString.append(h); } return hexString.toString(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return ""; }
From source file:com.sos.VirtualFileSystem.DataElements.SOSFileListEntry.java
private long doTransfer(final ISOSVirtualFile objInput, final ISOSVirtualFile objOutput) { @SuppressWarnings("unused") final String conMethodName = conClassName + "::doTransfer"; boolean flgClosingDone = false; if (objOutput == null) { RaiseException(SOSVfs_E_273.params("Target")); }//from w w w . ja v a2s . co m if (objInput == null) { RaiseException(SOSVfs_E_273.params("Source")); } boolean flgCreateSecurityHash = objOptions.CreateSecurityHash.value() && flgIsHashFile == false; MessageDigest md = null; if (flgCreateSecurityHash) { try { // TODO implement in value-method of securityhashtype md = MessageDigest.getInstance(objOptions.SecurityHashType.Value()); } catch (NoSuchAlgorithmException e1) { e1.printStackTrace(); flgCreateSecurityHash = false; } } executePreCommands(); long lngTotalBytesTransferred = 0; Base64 objBase64 = null; this.setStatus(enuTransferStatus.transferring); try { int intCumulativeFileSeperatorLength = 0; int lngBufferSize = objOptions.BufferSize.value(); byte[] buffer = new byte[lngBufferSize]; int intBytesTransferred; int intOffset = 0; boolean flgBase64EncodingOnOutput = false; boolean flgBase64EncodingOnInput = false; if (flgBase64EncodingOnOutput) { objBase64 = new Base64(); } synchronized (this) { if (objOptions.CumulateFiles.isTrue() && objOptions.CumulativeFileSeparator.IsNotEmpty()) { String strFS = objOptions.CumulativeFileSeparator.Value(); strFS = this.replaceVariables(strFS) + System.getProperty("line.separator"); byte[] bteB = strFS.getBytes(); intCumulativeFileSeperatorLength = bteB.length; objOutput.write(bteB); } if (objInput.getFileSize() <= 0) { objOutput.write(buffer, 0, 0); } else { while ((intBytesTransferred = objInput.read(buffer)) != -1) { try { int intBytes2Write = intBytesTransferred; if (flgBase64EncodingOnOutput) { byte[] bteIn = new byte[intBytesTransferred]; byte[] bteOut = objBase64.encode(bteIn); intBytes2Write = bteOut.length; buffer = bteOut; } objOutput.write(buffer, 0, intBytes2Write); } catch (JobSchedulerException e) { e.printStackTrace(System.err); break; } // TODO in case of wrong outputbuffer the handling of the error must be improved lngTotalBytesTransferred += intBytesTransferred; // intOffset += lngTotalBytesTransferred; setTransferProgress(lngTotalBytesTransferred); if (flgCreateSecurityHash) { md.update(buffer, 0, intBytesTransferred); } } } } objInput.closeInput(); objOutput.closeOutput(); flgClosingDone = true; if (flgCreateSecurityHash) { strMD5Hash = toHexString(md.digest()); logger.info(SOSVfs_I_274.params(strMD5Hash, strSourceTransferName, objOptions.SecurityHashType.Value())); if (objOptions.CreateSecurityHashFile.isTrue()) { JSTextFile objF = new JSTextFile(strSourceFileName + "." + objOptions.SecurityHashType.Value()); objF.WriteLine(strMD5Hash); objF.close(); objF.deleteOnExit(); } } // objDataTargetClient.CompletePendingCommand(); if (objDataTargetClient.isNegativeCommandCompletion()) { RaiseException( SOSVfs_E_175.params(objTargetTransferFile.getName(), objDataTargetClient.getReplyString())); } this.setNoOfBytesTransferred(lngTotalBytesTransferred); lngTotalBytesTransferred += intCumulativeFileSeperatorLength; executePostCommands(); return lngTotalBytesTransferred; } catch (Exception e) { RaiseException(e, SOSVfs_E_266.get()); } finally { if (flgClosingDone == false) { objInput.closeInput(); objOutput.closeOutput(); flgClosingDone = true; } } return lngTotalBytesTransferred; }