List of usage examples for java.security NoSuchAlgorithmException printStackTrace
public void printStackTrace()
From source file:com.workingagenda.devinettes.RiddlePanel.java
private String createHash(String g) { /*//from www. j av a 2s. c o m This method is from https://github.com/dillbyrne/HashPass/ blob/master/src/byrne/utilities/hashpass/HashPassActivity.java This will take in the guess and spit out the hash */ byte[] bytesOfMessage; try { bytesOfMessage = g.getBytes("UTF-8"); MessageDigest md; try { md = MessageDigest.getInstance("SHA1"); byte[] thedigest = md.digest(bytesOfMessage); final char[] HEX_CHARS = "0123456789abcdef".toCharArray(); StringBuilder sb = new StringBuilder(thedigest.length * 2); for (byte b : thedigest) { sb.append(HEX_CHARS[(b & 0xF0) >> 4]); sb.append(HEX_CHARS[b & 0x0F]); } return sb.toString(); //should not occur due to limited input choices // and no null options available } catch (NoSuchAlgorithmException nsae) { nsae.printStackTrace(); } //should not occur due to hard coded encoding choice } catch (UnsupportedEncodingException uee) { uee.printStackTrace(); } // returns null if it was unable to perform the hashing return null; }
From source file:com.mnxfst.stream.listener.webtrends.WebtrendsTokenRequest.java
private String getHMAC256(final String input, final String secret) { String temp = null;//from ww w . j a v a 2s . c om final SecretKeySpec keySpec = new SecretKeySpec(secret.getBytes(), "HmacSHA256"); try { final Mac mac = Mac.getInstance("HmacSHA256"); mac.init(keySpec); // update method adds the given byte to the Mac's input data. mac.update(input.getBytes()); final byte[] m = mac.doFinal(); // The base64-encoder in Commons Codec temp = base64Encode(m); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (InvalidKeyException e) { e.printStackTrace(); } return temp; }
From source file:com.aqnote.shared.cryptology.symmetric.Blowfish.java
/** * /* w w w .j a v a 2 s.c o m*/ * * @param name cipher name * @param provider provider name * @return Cipher */ private Cipher getCipher(String name, String provider) { Cipher cipher = null; try { cipher = Cipher.getInstance(name, provider); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (NoSuchProviderException e) { e.printStackTrace(); } catch (NoSuchPaddingException e) { e.printStackTrace(); } return cipher; }
From source file:com.constellio.app.modules.es.connectors.smb.security.WindowsPermissions.java
private void computePermissionsHash() { MessageDigest md;//from ww w . j av a 2 s.c o m try { md = MessageDigest.getInstance("MD5"); update(md, allowTokenDocument); update(md, denyTokenDocument); update(md, allowTokenShare); update(md, denyTokenShare); permissionsHash = Base64.encodeBase64String(md.digest()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } }
From source file:de.hska.ld.core.client.ClientRequest.java
private CloseableHttpClient createHttpsClient() throws IOException { SSLContext sslContext = null; try {/*w w w .ja v a 2 s . c o m*/ sslContext = SSLContexts.custom().loadTrustMaterial(null, new TrustStrategy() { @Override public boolean isTrusted(final X509Certificate[] chain, final String authType) throws CertificateException { return true; } }).useProtocol("TLSv1.2").build(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (KeyStoreException e) { e.printStackTrace(); } catch (KeyManagementException e) { e.printStackTrace(); } return HttpClients.custom().setSSLContext(sslContext).build(); }
From source file:com.hovans.netty.tcpsample.network.ChannelDecoder.java
public ChannelDecoder(Context context) { super();//w w w .j a v a2s .c o m mContext = context; try { mCipher = Cipher.getInstance("aes/cbc/pkcs5padding"); } catch (NoSuchAlgorithmException e) { // ? ?, ? e.printStackTrace(); throw new RuntimeException(e); } catch (NoSuchPaddingException e) { // ? ?, ? e.printStackTrace(); throw new RuntimeException(e); } }
From source file:com.rackspacecloud.client.cloudfiles.EasySSLSocketFactory.java
private SSLContext getSSLContext() throws IOException { if (this.sslcontext == null) { try {//from w w w .j a v a 2 s.co m this.sslcontext = createEasySSLContext(); } catch (NoSuchAlgorithmException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (KeyStoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return this.sslcontext; }
From source file:mvm.rya.mongodb.dao.SimpleMongoDBStorageStrategy.java
public BasicDBObject serializeInternal(RyaStatement statement) { String context = ""; if (statement.getContext() != null) { context = statement.getContext().getData(); }/* w w w. j av a 2s .c o m*/ String id = statement.getSubject().getData() + " " + statement.getPredicate().getData() + " " + statement.getObject().getData() + " " + context; byte[] bytes = id.getBytes(); try { MessageDigest digest = MessageDigest.getInstance("SHA-1"); bytes = digest.digest(bytes); } catch (NoSuchAlgorithmException e) { // TODO Auto-generated catch block e.printStackTrace(); } BasicDBObject doc = new BasicDBObject(ID, new String(Hex.encodeHex(bytes))) .append(SUBJECT, statement.getSubject().getData()) .append(PREDICATE, statement.getPredicate().getData()) .append(OBJECT, statement.getObject().getData()) .append(OBJECT_TYPE, statement.getObject().getDataType().toString()).append(CONTEXT, context); return doc; }
From source file:org.archive.modules.extractor.HTTPContentDigest.java
protected void innerProcess(CrawlURI curi) throws InterruptedException { // Ok, if we got this far we need to calculate the content digest. // Get the regex String regex = getStripRegex(); // Get a replay of the document character seq. ReplayCharSequence cs = null;/*from w w w . j av a 2 s. c o m*/ try { cs = curi.getRecorder().getContentReplayCharSequence(); // Create a MessageDigest MessageDigest digest = null; try { digest = MessageDigest.getInstance(SHA1); } catch (NoSuchAlgorithmException e1) { e1.printStackTrace(); return; } digest.reset(); String s = null; if (StringUtils.isEmpty(regex)) { s = cs.toString(); } else { // Process the document Matcher m = TextUtils.getMatcher(regex, cs); s = m.replaceAll(" "); TextUtils.recycleMatcher(m); } digest.update(s.getBytes()); // Get the new digest value byte[] newDigestValue = digest.digest(); // Save new digest value curi.setContentDigest(SHA1, newDigestValue); } catch (Exception e) { curi.getNonFatalFailures().add(e); logger.warning("Failed get of replay char sequence " + curi.toString() + " " + e.getMessage() + " " + Thread.currentThread().getName()); return; // Can't proceed if this happens. } }
From source file:com.raptureinvenice.webimageview.cache.WebImageCache.java
private String hashURLString(String urlString) { try {/*from w w w . j ava2 s .c o m*/ // Create MD5 Hash MessageDigest digest = java.security.MessageDigest.getInstance("MD5"); digest.update(urlString.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(); } //fall back to old method return urlString.replaceAll("[^A-Za-z0-9]", "#"); }