use of java.security.SecureRandom in project blade by biezhi.
the class HttpRequest method getTrustedFactory.
/**
* @return 返回SSL套接字工厂
* @throws HttpRequestException
*/
private static SSLSocketFactory getTrustedFactory() throws HttpRequestException {
if (TRUSTED_FACTORY == null) {
final TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
public void checkClientTrusted(X509Certificate[] chain, String authType) {
// Intentionally left blank
}
public void checkServerTrusted(X509Certificate[] chain, String authType) {
// Intentionally left blank
}
} };
try {
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, trustAllCerts, new SecureRandom());
TRUSTED_FACTORY = context.getSocketFactory();
} catch (GeneralSecurityException e) {
IOException ioException = new IOException("Security exception configuring SSL context");
ioException.initCause(e);
throw new HttpRequestException(ioException);
}
}
return TRUSTED_FACTORY;
}
use of java.security.SecureRandom in project spring-security by spring-projects.
the class SecureRandomFactoryBeanTests method testCreatesUsingDefaults.
@Test
public void testCreatesUsingDefaults() throws Exception {
SecureRandomFactoryBean factory = new SecureRandomFactoryBean();
Object result = factory.getObject();
assertThat(result).isInstanceOf(SecureRandom.class);
int rnd = ((SecureRandom) result).nextInt();
assertThat(rnd).isNotEqualTo(0);
}
use of java.security.SecureRandom in project spring-security by spring-projects.
the class SecureRandomFactoryBeanTests method testCreatesUsingSeed.
@Test
public void testCreatesUsingSeed() throws Exception {
SecureRandomFactoryBean factory = new SecureRandomFactoryBean();
Resource resource = new ClassPathResource("org/springframework/security/core/token/SecureRandomFactoryBeanTests.class");
assertThat(resource).isNotNull();
factory.setSeed(resource);
Object result = factory.getObject();
assertThat(result).isInstanceOf(SecureRandom.class);
int rnd = ((SecureRandom) result).nextInt();
assertThat(rnd).isNotEqualTo(0);
}
use of java.security.SecureRandom in project spring-security by spring-projects.
the class BCryptPasswordEncoderTests method customRandom.
@Test
public void customRandom() {
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(8, new SecureRandom());
String result = encoder.encode("password");
assertThat(encoder.matches("password", result)).isTrue();
}
use of java.security.SecureRandom in project spring-security by spring-projects.
the class BouncyCastleAesBytesEncryptorTest method setup.
@Before
public void setup() {
// generate random password, salt, and test data
SecureRandom secureRandom = new SecureRandom();
password = UUID.randomUUID().toString();
byte[] saltBytes = new byte[16];
secureRandom.nextBytes(saltBytes);
salt = new String(Hex.encode(saltBytes));
testData = new byte[1024 * 1024];
secureRandom.nextBytes(testData);
}
Aggregations