List of usage examples for java.security NoSuchAlgorithmException printStackTrace
public void printStackTrace()
From source file:de.hska.ld.content.client.PDFGenClient.java
private CloseableHttpClient createHttpsClient() throws IOException { SSLContext sslContext = null; try {/*from w ww . j a v a 2s. co 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:cn.vlabs.clb.server.web.FileInfo.java
public String getSHA256() throws IOException { File file = this.getFile(); BufferedInputStream in = new BufferedInputStream(new FileInputStream(file)); ByteArrayOutputStream out = new ByteArrayOutputStream(1024); byte[] temp = new byte[1024]; int size = 0; while ((size = in.read(temp)) != -1) { out.write(temp, 0, size);/* w w w . ja v a2 s . com*/ } in.close(); byte[] content = out.toByteArray(); MessageDigest digest; try { digest = MessageDigest.getInstance("SHA-256"); byte[] hash = digest.digest(content); String output = Hex.encodeHexString(hash); System.out.println(output); return output; } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return ""; }
From source file:com.talis.mapreduce.dicenc.SecondMapper.java
@Override public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException { String[] t = Utils.parseTripleOrQuad(value.toString()); MessageDigest digest = null;//from w ww. j av a 2 s.c om try { digest = MessageDigest.getInstance("MD5"); for (String n : t) { digest.update((n + "|").getBytes("UTF-8")); } String hash = new String(Hex.encodeHex(digest.digest())); context.write(new Text(t[0]), new Text(hash + "-s")); context.write(new Text(t[1]), new Text(hash + "-p")); context.write(new Text(t[2]), new Text(hash + "-o")); if (t.length == 4) { context.write(new Text(t[3]), new Text(hash + "-g")); } } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } }
From source file:com.wunding.mlplayer.hudong.DummySSLSocketFactory.java
public DummySSLSocketFactory() { try {/*from ww w . ja v a2 s .c om*/ SSLContext sslcontent = SSLContext.getInstance("TLS"); sslcontent.init(null, // KeyManager not required new TrustManager[] { new DummyTrustManager() }, null); factory = sslcontent.getSocketFactory(); // factory = new org.apache.http.conn.ssl.SSLSocketFactory(sslcontent); // // Accept any hostname, so the self-signed certificates don't fail // factory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER) } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (KeyManagementException e) { e.printStackTrace(); } }
From source file:corner.services.impl.DESedeEncryptServiceImpl.java
public byte[] encrypt(byte[] src, byte[] key) { try {// www.j a va 2 s . c o m SecretKey deskey = new SecretKeySpec(key, Algorithm); Cipher c1 = Cipher.getInstance(Algorithm); c1.init(Cipher.ENCRYPT_MODE, deskey); return c1.doFinal(src); } catch (java.security.NoSuchAlgorithmException e1) { e1.printStackTrace(); } catch (javax.crypto.NoSuchPaddingException e2) { e2.printStackTrace(); } catch (java.lang.Exception e3) { e3.printStackTrace(); } return null; }
From source file:corner.services.impl.DESedeEncryptServiceImpl.java
public byte[] decrypt(byte[] src, byte[] keybyte) { try {//w w w . jav a 2s . c om SecretKey deskey = new SecretKeySpec(keybyte, Algorithm); Cipher c1 = Cipher.getInstance(Algorithm); c1.init(Cipher.DECRYPT_MODE, deskey); return c1.doFinal(src); } catch (java.security.NoSuchAlgorithmException e1) { e1.printStackTrace(); } catch (javax.crypto.NoSuchPaddingException e2) { e2.printStackTrace(); } catch (java.lang.Exception e3) { e3.printStackTrace(); } return null; }
From source file:edu.cmu.sei.ams.cloudlet.impl.AESEncrypter.java
public AESEncrypter(String password) { this.password = password; try {//www .j a v a 2 s . co m MessageDigest digest = MessageDigest.getInstance("SHA-256"); digest.reset(); this.skeySpec = new SecretKeySpec(digest.digest(this.password.getBytes("UTF-8")), "AES"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } }
From source file:org.craftercms.commons.crypto.SimpleAesCipher.java
public SimpleAesCipher(String base64Key) { KeyGenerator kgen = null;//from w ww . j a v a 2 s . c o m try { kgen = KeyGenerator.getInstance("AES"); } catch (NoSuchAlgorithmException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } kgen.init(128); // 192 and 256 bits may not be available byte[] raw = Base64.decodeBase64(base64Key); skeySpec = new SecretKeySpec(raw, "AES"); try { cipher = Cipher.getInstance("AES"); } catch (NoSuchAlgorithmException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchPaddingException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.sldeditor.common.property.EncryptedPropertiesApache.java
@Override public void initialise(String password) { PBEParameterSpec ps = new javax.crypto.spec.PBEParameterSpec(salt, 20); SecretKeyFactory kf;/*w w w . java 2s . co m*/ try { kf = SecretKeyFactory.getInstance("PBEWithMD5AndDES"); SecretKey k = kf.generateSecret(new javax.crypto.spec.PBEKeySpec(password.toCharArray())); encrypter = Cipher.getInstance("PBEWithMD5AndDES/CBC/PKCS5Padding"); decrypter = Cipher.getInstance("PBEWithMD5AndDES/CBC/PKCS5Padding"); encrypter.init(Cipher.ENCRYPT_MODE, k, ps); decrypter.init(Cipher.DECRYPT_MODE, k, ps); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (NoSuchPaddingException e) { e.printStackTrace(); } catch (InvalidKeySpecException e) { e.printStackTrace(); } catch (InvalidKeyException e) { e.printStackTrace(); } catch (InvalidAlgorithmParameterException e) { e.printStackTrace(); } }
From source file:net.eve.finger.server.InternalDBAuth.java
/** * Default constructor.//from w w w. j a v a2 s .c o m */ public InternalDBAuth() { // Setup the password hasher try { SHA256 = MessageDigest.getInstance("SHA-256"); } catch (NoSuchAlgorithmException ex) { SHA256 = null; ex.printStackTrace(); } }