List of usage examples for java.security NoSuchAlgorithmException printStackTrace
public void printStackTrace()
From source file:com.miapc.ipudong.Application.java
@Bean public RestTemplate getRestTemplate() { SSLContext sslcontext = null; Set<KeyManager> keymanagers = new LinkedHashSet<>(); Set<TrustManager> trustmanagers = new LinkedHashSet<>(); try {/* www .ja va2s . c o m*/ trustmanagers.add(new HttpsTrustManager()); KeyManager[] km = keymanagers.toArray(new KeyManager[keymanagers.size()]); TrustManager[] tm = trustmanagers.toArray(new TrustManager[trustmanagers.size()]); sslcontext = SSLContexts.custom().build(); sslcontext.init(km, tm, new SecureRandom()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (KeyManagementException e) { e.printStackTrace(); } SSLConnectionSocketFactory factory = new SSLConnectionSocketFactory(sslcontext, SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); HttpClientBuilder httpClientBuilder = HttpClients.custom(); httpClientBuilder.setSSLSocketFactory(factory); // ?3? httpClientBuilder.setRetryHandler(new DefaultHttpRequestRetryHandler(2, true)); // ????Keep-Alive httpClientBuilder.setKeepAliveStrategy(new DefaultConnectionKeepAliveStrategy()); List<Header> headers = new ArrayList<>(); headers.add(new BasicHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.16 Safari/537.36")); headers.add(new BasicHeader("Accept-Encoding", "gzip,deflate")); headers.add(new BasicHeader("Accept-Language", "zh-CN")); headers.add(new BasicHeader("Connection", "Keep-Alive")); headers.add(new BasicHeader("Authorization", "reslibu")); httpClientBuilder.setDefaultHeaders(headers); CloseableHttpClient httpClient = httpClientBuilder.build(); if (httpClient != null) { // httpClient??RequestConfig HttpComponentsClientHttpRequestFactory clientHttpRequestFactory = new HttpComponentsClientHttpRequestFactory( httpClient); // clientHttpRequestFactory.setConnectTimeout(60 * 1000); // ???SocketTimeout clientHttpRequestFactory.setReadTimeout(5 * 60 * 1000); // ???? clientHttpRequestFactory.setConnectionRequestTimeout(5000); // ?truePOSTPUT????false? // clientHttpRequestFactory.setBufferRequestBody(false); // ? List<HttpMessageConverter<?>> messageConverters = new ArrayList<>(); messageConverters.add(new StringHttpMessageConverter(Charset.forName("UTF-8"))); messageConverters.add(new MappingJackson2HttpMessageConverter()); messageConverters.add(new FormHttpMessageConverter()); messageConverters.add(new MappingJackson2XmlHttpMessageConverter()); RestTemplate restTemplate = new RestTemplate(messageConverters); restTemplate.setRequestFactory(clientHttpRequestFactory); restTemplate.setErrorHandler(new DefaultResponseErrorHandler()); return restTemplate; } else { return null; } }
From source file:fr.tse.fi2.hpp.labs.queries.impl.lab5.BloomFilterQuery.java
@Override protected void process(DebsRecord record) { // TODO Auto-generated method stub String str = record.getHack_license() + record.getDropoff_latitude() + record.getDropoff_longitude() + record.getPickup_latitude() + record.getPickup_longitude(); MessageDigest md = null;//from www.ja v a 2s . c om try { md = MessageDigest.getInstance("SHA-256"); } catch (NoSuchAlgorithmException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } String[] str2hash = new String[k]; for (int i = 0; i < 10; i++) { str2hash[i] = salt[i] + str; try { md.update(str2hash[i].toString().getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } byte[] res = md.digest(); BigInteger indiceB = new BigInteger(res); int indice = indiceB.intValue(); if (indice < 0) indice = -indice; indice = indice % 14378; if (!bloomFilter.get(indice)) bloomFilter.set(indice); } }
From source file:org.hachreak.projects.networkcodingsip2peer.behavior.RetrieveEncodedFileClientBehavior.java
public void run() { try {/*from ww w . j a v a 2 s .c o m*/ retrieveEncodedFragments(); } catch (NoSuchAlgorithmException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.magnet.mmx.server.plugin.mmxmgmt.servlet.integration.IntegrationChannelResource.java
private static String generateHash(PublishMessageToChatRequest request) { List<String> recipients = new ArrayList<String>(); recipients.addAll(Arrays.asList(request.getRecipients())); recipients.add(request.getUserId()); if (recipients != null && recipients.size() > 0) { //order recipients Collections.sort(recipients); String signature = StringUtils.join(recipients, ","); MessageDigest md5 = null; try {/* w ww.j a va 2 s . c o m*/ md5 = MessageDigest.getInstance("MD5"); md5.update((MMX_INTERNAL_SALT + signature).getBytes()); byte byteData[] = md5.digest(); String channelHash = encode2Hex(byteData); return channelHash; } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } } return null; }
From source file:org.hil.systemadministrator.systemusermanagement.service.impl.SystemUserManagerImpl.java
public List<SystemUser> saveSystemUser(SystemUser systemUser, SystemAccount systemAccount, boolean newPw) { if (systemUser.getId() == null || systemUser.getId() == 0) { List<SystemAccount> tmp = systemAccountDao.findByAccountName(systemAccount.getAccountName()); if (tmp != null && tmp.size() > 0) return null; }//from w w w . j a v a2s. com String md5Password = ""; if (newPw) { try { md5Password = MD5.MD5(systemAccount.getPassword().toLowerCase()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } systemAccount.setPassword(md5Password); } systemAccount = systemAccountDao.save(systemAccount); if (systemUser.getId() == null || systemUser.getId() == 0) systemUser.setSystemAccount(systemAccount); systemUserDao.save(systemUser); return systemUserDao.getAll(null, null); }
From source file:com.mobileman.projecth.web.util.PersistentCookieHelper.java
private String createHash(String salt, User user) { StringBuilder sb = new StringBuilder(); sb.append(salt);//from www .jav a 2 s . co m sb.append(user.getId()); sb.append(user.getName().getName()); sb.append(user.getName().getSurname()); sb.append(user.getUserAccount().getEmail()); MessageDigest md; try { md = MessageDigest.getInstance("SHA-1"); byte[] src = sb.toString().getBytes("utf-8"); md.update(src, 0, src.length); byte[] sha1hash = new byte[40]; sha1hash = md.digest(); String sha1 = convertToHex(sha1hash); sb.delete(0, sb.length()); sb.append(user.getId()); sb.append(SEPARATOR); sb.append(salt); sb.append(SEPARATOR); sb.append(sha1); return sb.toString(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return ""; }
From source file:de.alvaro.cordova.aes.Aes.java
private void initAES(String clientId) { try {//from w w w . ja v a 2s . c o m aesEn = new AESEncrypter(); String callbacckk = aesEn.m4413a(clientId); //CallbackContext.sendPluginResult(callbacckk); PluginResult result = new PluginResult(PluginResult.Status.OK, callbacckk); result.setKeepCallback(true); mCallbackContext.sendPluginResult(result); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (NoSuchPaddingException e) { e.printStackTrace(); } catch (InvalidKeyException e) { e.printStackTrace(); } catch (InvalidAlgorithmParameterException e) { e.printStackTrace(); } catch (IllegalBlockSizeException e) { e.printStackTrace(); } catch (BadPaddingException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } }
From source file:edu.umkc.sce.VpQuery.java
byte[] getResultHash(ResultSet results) { MessageDigest md = null;// w ww .j a v a 2 s . c om ; try { md = MessageDigest.getInstance(MessageDigestAlgorithms.MD5); } catch (NoSuchAlgorithmException e) { // TODO Auto-generated catch block e.printStackTrace(); } while (results.hasNext()) { QuerySolution sol = results.nextSolution(); Iterator<String> col = sol.varNames(); while (col.hasNext()) { md.update(sol.get(col.next()).asNode().toString().getBytes()); } } return md.digest(); }
From source file:com.mastercard.walletservices.mdes.DeviceInfo.java
/** * Return ByteArray of device finger print. * * @return The Device Finger Pring as String */// ww w . j a v a2 s .c o m public String getDeviceFingerprint() { byte[] dataBytes = (this.deviceName + this.deviceType + this.imei + this.msisdn + this.nfcCapable + this.osName).getBytes(); ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[dataBytes.length]); byteBuffer.put(dataBytes); // Create MessageDigest using SHA-256 algorithm Added required MessageDigest messageDigest; try { messageDigest = MessageDigest.getInstance("SHA-256"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); return null; } // Hash the result byte[] hash = messageDigest.digest(byteBuffer.array()); // Return Hex return new String(Hex.encodeHex(hash)); }
From source file:com.example.jinux.mydemo.s3.UploadService.java
private String md5(String s) { try {/*from w w w .j a v a 2 s. co 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 null; } }