List of usage examples for java.security NoSuchAlgorithmException printStackTrace
public void printStackTrace()
From source file:org.berlin_vegan.bvapp.acra.ACRAPostSender.java
private static String md5(String s) { MessageDigest m = null;//w w w. j a v a 2 s . c om try { m = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } m.update(s.getBytes(), 0, s.length()); return new BigInteger(1, m.digest()).toString(16); }
From source file:net.blogracy.model.hashes.Hashes.java
/** * Creates an hash from a {@code String} * * @param value is the {@code String} to be hashed * @return the Hash of {@param value}//from w ww . ja v a 2 s . c o m */ static public Hash newHash(String value) { Hash result = null; try { MessageDigest digester = MessageDigest.getInstance("SHA-1"); final byte[] hash = digester.digest(value.getBytes()); result = new HashImpl(hash); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return result; }
From source file:Main.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) private static void generateNewKeyOld(Context context) { try {// w w w . java 2 s .c o m KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(KeyProperties.KEY_ALGORITHM_RSA, KEY_PROVIDER); Calendar instance = Calendar.getInstance(); Date start = instance.getTime(); instance.add(Calendar.YEAR, 1); Date end = instance.getTime(); keyPairGenerator.initialize(new KeyPairGeneratorSpec.Builder(context).setAlias(KEY_ALIAS) .setSubject(new X500Principal("CN=" + KEY_ALIAS)).setSerialNumber(BigInteger.valueOf(20151021)) .setStartDate(start).setEndDate(end).build()); keyPairGenerator.generateKeyPair(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (NoSuchProviderException e) { e.printStackTrace(); } catch (InvalidAlgorithmParameterException e) { e.printStackTrace(); } }
From source file:cn.com.qiqi.order.utils.Encodes.java
public static String md5(String rawPass, Object salt, int iterations) { try {//from w w w .j ava 2 s. c om String saltedPass = mergePasswordAndSalt(rawPass, salt, false); MessageDigest messageDigest = MessageDigest.getInstance("md5"); byte[] digest = messageDigest.digest(saltedPass.getBytes()); for (int i = 1; i < 1; i++) { digest = messageDigest.digest(digest); } return encodeHex(digest); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return ""; }
From source file:com.jt.https.test.send.java
public static String PostTo(String content) { String responseMessage = null; String filePath = ""; if (!filePath.endsWith("/")) { filePath = filePath + "/"; }//from ww w .jav a 2 s . c om HttpClient httpclient = new DefaultHttpClient(); try { KeyStore keystore = KeyStore.getInstance("jks"); KeyStore trustStore = KeyStore.getInstance("jks"); FileInputStream keystoreInstream = new FileInputStream( new File("F:\\temp\\?\\lz\\\\bis-stg-sdb.jks")); FileInputStream trustStoreInstream = new FileInputStream( new File("F:\\temp\\?\\lz\\\\EXV_GROUP_BIS_IFRONT_JTLZX_100.jks")); //FileInputStream keystoreInstream = new FileInputStream(new File("F:\\temp\\?\\lz\\\\pingan2jiangtai_test.jks")); //FileInputStream trustStoreInstream = new FileInputStream(new File("F:\\temp\\?\\lz\\\\pingan2jiangtai_test_trust.jks")); try { keystore.load(keystoreInstream, "123456".toCharArray()); trustStore.load(trustStoreInstream, "paic1234".toCharArray()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (CertificateException e) { e.printStackTrace(); } finally { keystoreInstream.close(); trustStoreInstream.close(); } SSLSocketFactory socketFactory = new SSLSocketFactory(SSLSocketFactory.SSL, keystore, "123456", trustStore, null, new TrustStrategy() { public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException { return true; } }, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); Scheme sch = new Scheme("https", 8107, socketFactory); httpclient.getConnectionManager().getSchemeRegistry().register(sch); HttpPost post = new HttpPost("https://222.68.184.181:8107"); StringEntity entity = new StringEntity(content, "text/html", "UTF-8"); post.setEntity(entity); HttpResponse res = httpclient.execute(post); HttpEntity resEntity = res.getEntity(); if (resEntity != null) { responseMessage = convertStreamToString(resEntity.getContent()); System.out.println("???" + content); System.out.println("?" + responseMessage); } } catch (KeyStoreException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (KeyManagementException e) { e.printStackTrace(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (UnrecoverableKeyException e) { e.printStackTrace(); } finally { httpclient.getConnectionManager().shutdown(); } return responseMessage; }
From source file:org.gss_project.gss.web.client.TestClient.java
public static String sign(String httpMethod, String timestamp, String path, String token) { String input = httpMethod + timestamp + path; String signed = null;//www . j av a 2s . c om try { System.err.println("Token:" + token); // Get an HMAC-SHA1 key from the authentication token. System.err.println("Input: " + input); SecretKeySpec signingKey = new SecretKeySpec(Base64.decodeBase64(token.getBytes()), "HmacSHA1"); // Get an HMAC-SHA1 Mac instance and initialize with the signing key. Mac hmac = Mac.getInstance("HmacSHA1"); hmac.init(signingKey); // Compute the HMAC on the input data bytes. byte[] rawMac = hmac.doFinal(input.getBytes()); // Do base 64 encoding. signed = new String(Base64.encodeBase64(rawMac), "US-ASCII"); } catch (InvalidKeyException ikex) { System.err.println("Fatal key exception: " + ikex.getMessage()); ikex.printStackTrace(); } catch (UnsupportedEncodingException ueex) { System.err.println("Fatal encoding exception: " + ueex.getMessage()); } catch (NoSuchAlgorithmException nsaex) { System.err.println("Fatal algorithm exception: " + nsaex.getMessage()); nsaex.printStackTrace(); } if (signed == null) System.exit(-1); System.err.println("Signed: " + signed); return signed; }
From source file:com.google.samples.apps.abelana.AbelanaThings.java
private static String signData(String data) { try {//from www .ja v a 2 s.c om if (signer == null) { signer = Signature.getInstance("SHA256withRSA"); signer.initSign(credential.getServiceAccountPrivateKey()); } signer.update(data.getBytes("UTF-8")); byte[] rawSignature = signer.sign(); return new String(Base64.encode(rawSignature, Base64.DEFAULT)); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (InvalidKeyException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (SignatureException e) { e.printStackTrace(); } return null; }
From source file:test.TestFinal.java
public static JerseyClient getJerseyClient(boolean isSSL) { ClientBuilder clientBuilder = JerseyClientBuilder.newBuilder().register(MultiPartFeature.class); // Create a secure JerseyClient if (isSSL) {//from w w w .j ava 2 s . c o m try { HostnameVerifier verifier = new HostnameVerifier() { public boolean verify(String hostname, SSLSession session) { return true; } }; TrustManager[] tm = new TrustManager[] { new X509TrustManager() { public X509Certificate[] getAcceptedIssuers() { return null; } public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { } public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { } } }; SSLContext sslContext = sslContext = SSLContext.getInstance("SSL"); sslContext.init(null, tm, new SecureRandom()); clientBuilder.sslContext(sslContext).hostnameVerifier(verifier); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (KeyManagementException e) { e.printStackTrace(); } } return (JerseyClient) clientBuilder.build().register(JacksonJsonProvider.class); }
From source file:org.mozilla.android.sync.Cryptographer.java
private static Cipher getCipher() { Cipher cipher = null;/*from ww w.ja v a2 s . c om*/ try { cipher = Cipher.getInstance(TRANSFORMATION); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (NoSuchPaddingException e) { e.printStackTrace(); } return cipher; }
From source file:Main.java
public static byte[] aesIGEencrypt(byte[] tmpAESiv, byte[] tmpAesKey, byte[] data) { try {/* ww w . ja v a 2 s .c om*/ ByteBuffer out = ByteBuffer.allocate(data.length); byte[] ivp = Arrays.copyOfRange(tmpAESiv, 0, tmpAESiv.length / 2); byte[] iv2p = Arrays.copyOfRange(tmpAESiv, tmpAESiv.length / 2, tmpAESiv.length); int len = data.length / AES_BLOCK_SIZE; byte[] xorInput = null; byte[] xorOutput = null; SecretKeySpec keySpec = null; keySpec = new SecretKeySpec(tmpAesKey, "AES"); Cipher cipher = null; cipher = Cipher.getInstance("AES/ECB/NoPadding"); cipher.init(Cipher.ENCRYPT_MODE, keySpec); byte[] input = null; byte[] output = null; for (int i = 0; i < len; i++) { input = Arrays.copyOfRange(data, i * AES_BLOCK_SIZE, (i + 1) * AES_BLOCK_SIZE); xorInput = xor(input, ivp); output = cipher.doFinal(xorInput); xorOutput = xor(output, iv2p); out.put(xorOutput); ivp = xorOutput; iv2p = input; } return out.array(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (NoSuchPaddingException e) { e.printStackTrace(); } catch (IllegalBlockSizeException e) { e.printStackTrace(); } catch (BadPaddingException e) { e.printStackTrace(); } catch (InvalidKeyException e) { e.printStackTrace(); } return null; }