List of usage examples for java.security SecureRandom SecureRandom
public SecureRandom()
From source file:com.zimbra.cs.account.CsrfTokenKey.java
/** * @param version// ww w. j av a 2 s .c om * @param key * @throws ServiceException */ CsrfTokenKey(long version, byte[] key) throws ServiceException { keyVersion = version; keyCreatedAt = System.currentTimeMillis(); if (key != null) { csrfTokenKey = key; } else { SecureRandom random = new SecureRandom(); csrfTokenKey = new byte[KEY_SIZE_BYTES]; random.nextBytes(csrfTokenKey); } }
From source file:org.fineract.module.stellar.fineractadapter.RestAdapterProvider.java
OkHttpClient createClient() { final OkHttpClient client = new OkHttpClient(); final TrustManager[] certs = new TrustManager[] { new X509TrustManager() { @Override/*from w w w.java2 s . c om*/ public X509Certificate[] getAcceptedIssuers() { return null; } @Override public void checkServerTrusted(final X509Certificate[] chain, final String authType) throws CertificateException { } @Override public void checkClientTrusted(final X509Certificate[] chain, final String authType) throws CertificateException { } } }; SSLContext ctx = null; try { ctx = SSLContext.getInstance("TLS"); ctx.init(null, certs, new SecureRandom()); } catch (final java.security.GeneralSecurityException ignored) { } try { client.setHostnameVerifier((hostname, session) -> true); if (ctx != null) { client.setSslSocketFactory(ctx.getSocketFactory()); } } catch (final Exception ignored) { } return client; }
From source file:fr.cph.stock.security.SecurityServiceImpl.java
/** * Generate a salt, a random key, en encrypt it * * @return a key encrypted/* www .ja v a 2 s . c om*/ * @throws NoSuchAlgorithmException the NoSuchAlgorithmException * @throws UnsupportedEncodingException the UnsupportedEncodingException */ @Override public String generateSalt() throws NoSuchAlgorithmException, UnsupportedEncodingException { final SecureRandom random = new SecureRandom(); return encodeToSha256(random.toString()); }
From source file:io.pivotal.strepsirrhini.chaoslemur.Application.java
@Bean Random random() { return new SecureRandom(); }
From source file:com.intel.chimera.codec.JceAesCtrCryptoCodec.java
public JceAesCtrCryptoCodec(Properties props) { provider = Utils.getJCEProvider(props); final String secureRandomAlg = Utils.getSecureRandomAlg(props); try {/*from ww w. j av a 2s . co m*/ random = (provider != null) ? SecureRandom.getInstance(secureRandomAlg, provider) : SecureRandom.getInstance(secureRandomAlg); } catch (GeneralSecurityException e) { LOG.warn(e.getMessage()); random = new SecureRandom(); } }
From source file:com.github.horrorho.inflatabledonkey.cloud.escrow.EscrowOperationsRecover.java
public static NSDictionary recover(HttpClient httpClient, EscrowProxyRequestFactory requests) throws IOException { SRPClient srpClient = SRPFactory.rfc5054(new SecureRandom()); NSDictionary srpInitResponse = srpInit(httpClient, requests, srpClient); NSDictionary recover = recover(httpClient, requests, srpClient, srpInitResponse); NSDictionary decrypt = decrypt(srpClient, recover); logger.debug("-- recover() - escrowed data: {}", decrypt.toXMLPropertyList()); return decrypt; }
From source file:com.zimbra.cs.account.AuthTokenKey.java
AuthTokenKey(long version, byte[] key) throws ServiceException { mVersion = version;//ww w . j a va 2 s.c om mCreated = System.currentTimeMillis(); if (key != null) { mKey = key; } else { SecureRandom random = new SecureRandom(); mKey = new byte[KEY_SIZE_BYTES]; random.nextBytes(mKey); } }
From source file:com.intel.cryptostream.OpensslAesCtrCryptoCodec.java
public OpensslAesCtrCryptoCodec() { String loadingFailureReason = OpensslCipher.getLoadingFailureReason(); if (loadingFailureReason != null) { throw new RuntimeException(loadingFailureReason); }/* ww w.j a v a2 s.c om*/ final Class<? extends Random> klass = CryptoStreamUtils.getSecureRandomClass(); try { random = ReflectionUtils.newInstance(klass); } catch (Exception e) { LOG.info("Unable to use " + klass.getName() + ". Falling back to " + "Java SecureRandom.", e); this.random = new SecureRandom(); } }
From source file:com.androidinahurry.network.utils.FakeSSLSocketFactory.java
public FakeSSLSocketFactory(KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException { super(null);/*ww w.j a v a2 s . c o m*/ try { SSLContext context = SSLContext.getInstance("TLS"); // Create a trust manager that does not validate certificate chains // and simply // accept all type of certificates TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { public java.security.cert.X509Certificate[] getAcceptedIssuers() { return new java.security.cert.X509Certificate[] {}; } public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { } public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { } } }; // Initialize the socket factory context.init(null, trustAllCerts, new SecureRandom()); sslFactory = context.getSocketFactory(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.intel.chimera.CryptoCodecTest.java
@Before public void setUp() throws IOException { Random random = new SecureRandom(); random.nextBytes(key);/* w ww . ja v a2 s . c o m*/ random.nextBytes(iv); props = new Properties(); }