private SecureRandom createSecureRandom(ContextAware context) throws NoSuchProviderException, NoSuchAlgorithmException { SecureRandom secureRandom = getSecureRandom().createSecureRandom(); context.addInfo("secure random algorithm '" + secureRandom.getAlgorithm() + "' provider '" + secureRandom.getProvider() + "'"); return secureRandom; }
/** * Gets the secure random generator configuration. * @return secure random factory bean; if no secure random generator * configuration has been set, a default factory bean is returned */ public SecureRandomFactoryBean getSecureRandom() { if (secureRandom == null) { return new SecureRandomFactoryBean(); } return secureRandom; }
/** * Creates a new {@link SecureRandom} generator using the receiver's * configuration. * @return secure random generator instance * @throws NoSuchProviderException if the provider name specified by * {@link #setProvider(String)} is not known to the platform * @throws NoSuchAlgorithmException if the algorithm name specified by * {@link #setAlgorithm(String)} is not recognized by the specified * provider (or the platform's default provider if the provider isn't * specified) */ public SecureRandom createSecureRandom() throws NoSuchProviderException, NoSuchAlgorithmException { try { return getProvider() != null ? SecureRandom.getInstance(getAlgorithm(), getProvider()) : SecureRandom.getInstance(getAlgorithm()); } catch (NoSuchProviderException ex) { throw new NoSuchProviderException("no such secure random provider: " + getProvider()); } catch (NoSuchAlgorithmException ex) { throw new NoSuchAlgorithmException("no such secure random algorithm: " + getAlgorithm()); } }
@Test public void testExplicitProvider() throws Exception { SecureRandom secureRandom = SecureRandom.getInstance( SSL.DEFAULT_SECURE_RANDOM_ALGORITHM); factoryBean.setProvider(secureRandom.getProvider().getName()); assertNotNull(factoryBean.createSecureRandom()); }
@Test public void testUnknownAlgorithm() throws Exception { factoryBean.setAlgorithm(SSLTestConstants.FAKE_ALGORITHM_NAME); try { factoryBean.createSecureRandom(); fail("expected NoSuchAlgorithmException"); } catch (NoSuchAlgorithmException ex) { assertTrue(ex.getMessage().contains(SSLTestConstants.FAKE_ALGORITHM_NAME)); } }
@Test public void testUnknownProvider() throws Exception { factoryBean.setProvider(SSLTestConstants.FAKE_PROVIDER_NAME); try { factoryBean.createSecureRandom(); fail("expected NoSuchProviderException"); } catch (NoSuchProviderException ex) { assertTrue(ex.getMessage().contains(SSLTestConstants.FAKE_PROVIDER_NAME)); } }
/** * Creates a new {@link SecureRandom} generator using the receiver's * configuration. * @return secure random generator instance * @throws NoSuchProviderException if the provider name specified by * {@link #setProvider(String)} is not known to the platform * @throws NoSuchAlgorithmException if the algorithm name specified by * {@link #setAlgorithm(String)} is not recognized by the specified * provider (or the platform's default provider if the provider isn't * specified) */ public SecureRandom createSecureRandom() throws NoSuchProviderException, NoSuchAlgorithmException { try { return getProvider() != null ? SecureRandom.getInstance(getAlgorithm(), getProvider()) : SecureRandom.getInstance(getAlgorithm()); } catch (NoSuchProviderException ex) { throw new NoSuchProviderException("no such secure random provider: " + getProvider()); } catch (NoSuchAlgorithmException ex) { throw new NoSuchAlgorithmException("no such secure random algorithm: " + getAlgorithm()); } }
@Override public SecureRandom createSecureRandom() throws NoSuchProviderException, NoSuchAlgorithmException { secureRandomCreated = true; return super.createSecureRandom(); }
/** * Gets the secure random generator configuration. * @return secure random factory bean; if no secure random generator * configuration has been set, a default factory bean is returned */ public SecureRandomFactoryBean getSecureRandom() { if (secureRandom == null) { return new SecureRandomFactoryBean(); } return secureRandom; }
/** * Creates a new {@link SecureRandom} generator using the receiver's * configuration. * @return secure random generator instance * @throws NoSuchProviderException if the provider name specified by * {@link #setProvider(String)} is not known to the platform * @throws NoSuchAlgorithmException if the algorithm name specified by * {@link #setAlgorithm(String)} is not recognized by the specified * provider (or the platform's default provider if the provider isn't * specified) */ public SecureRandom createSecureRandom() throws NoSuchProviderException, NoSuchAlgorithmException { try { return getProvider() != null ? SecureRandom.getInstance(getAlgorithm(), getProvider()) : SecureRandom.getInstance(getAlgorithm()); } catch (NoSuchProviderException ex) { throw new NoSuchProviderException("no such secure random provider: " + getProvider()); } catch (NoSuchAlgorithmException ex) { throw new NoSuchAlgorithmException("no such secure random algorithm: " + getAlgorithm()); } }
private SecureRandom createSecureRandom(ContextAware context) throws NoSuchProviderException, NoSuchAlgorithmException { SecureRandom secureRandom = getSecureRandom().createSecureRandom(); context.addInfo("secure random algorithm '" + secureRandom.getAlgorithm() + "' provider '" + secureRandom.getProvider() + "'"); return secureRandom; }
/** * Gets the secure random generator configuration. * @return secure random factory bean; if no secure random generator * configuration has been set, a default factory bean is returned */ public SecureRandomFactoryBean getSecureRandom() { if (secureRandom == null) { return new SecureRandomFactoryBean(); } return secureRandom; }
/** * Creates a new {@link SecureRandom} generator using the receiver's * configuration. * @return secure random generator instance * @throws NoSuchProviderException if the provider name specified by * {@link #setProvider(String)} is not known to the platform * @throws NoSuchAlgorithmException if the algorithm name specified by * {@link #setAlgorithm(String)} is not recognized by the specified * provider (or the platform's default provider if the provider isn't * specified) */ public SecureRandom createSecureRandom() throws NoSuchProviderException, NoSuchAlgorithmException { try { return getProvider() != null ? SecureRandom.getInstance(getAlgorithm(), getProvider()) : SecureRandom.getInstance(getAlgorithm()); } catch (NoSuchProviderException ex) { throw new NoSuchProviderException("no such secure random provider: " + getProvider()); } catch (NoSuchAlgorithmException ex) { throw new NoSuchAlgorithmException("no such secure random algorithm: " + getAlgorithm()); } }
private SecureRandom createSecureRandom(ContextAware context) throws NoSuchProviderException, NoSuchAlgorithmException { SecureRandom secureRandom = getSecureRandom().createSecureRandom(); context.addInfo("secure random algorithm '" + secureRandom.getAlgorithm() + "' provider '" + secureRandom.getProvider() + "'"); return secureRandom; }
/** * Gets the secure random generator configuration. * @return secure random factory bean; if no secure random generator * configuration has been set, a default factory bean is returned */ public SecureRandomFactoryBean getSecureRandom() { if (secureRandom == null) { return new SecureRandomFactoryBean(); } return secureRandom; }
/** * Creates a new {@link SecureRandom} generator using the receiver's * configuration. * @return secure random generator instance * @throws NoSuchProviderException if the provider name specified by * {@link #setProvider(String)} is not known to the platform * @throws NoSuchAlgorithmException if the algorithm name specified by * {@link #setAlgorithm(String)} is not recognized by the specified * provider (or the platform's default provider if the provider isn't * specified) */ public SecureRandom createSecureRandom() throws NoSuchProviderException, NoSuchAlgorithmException { try { return getProvider() != null ? SecureRandom.getInstance(getAlgorithm(), getProvider()) : SecureRandom.getInstance(getAlgorithm()); } catch (NoSuchProviderException ex) { throw new NoSuchProviderException("no such secure random provider: " + getProvider()); } catch (NoSuchAlgorithmException ex) { throw new NoSuchAlgorithmException("no such secure random algorithm: " + getAlgorithm()); } }
private SecureRandom createSecureRandom(ContextAware context) throws NoSuchProviderException, NoSuchAlgorithmException { SecureRandom secureRandom = getSecureRandom().createSecureRandom(); context.addInfo("secure random algorithm '" + secureRandom.getAlgorithm() + "' provider '" + secureRandom.getProvider() + "'"); return secureRandom; }
/** * Gets the secure random generator configuration. * @return secure random factory bean; if no secure random generator * configuration has been set, a default factory bean is returned */ public SecureRandomFactoryBean getSecureRandom() { if (secureRandom == null) { return new SecureRandomFactoryBean(); } return secureRandom; }
/** * Creates a new {@link SecureRandom} generator using the receiver's * configuration. * @return secure random generator instance * @throws NoSuchProviderException if the provider name specified by * {@link #setProvider(String)} is not known to the platform * @throws NoSuchAlgorithmException if the algorithm name specified by * {@link #setAlgorithm(String)} is not recognized by the specified * provider (or the platform's default provider if the provider isn't * specified) */ public SecureRandom createSecureRandom() throws NoSuchProviderException, NoSuchAlgorithmException { try { return getProvider() != null ? SecureRandom.getInstance(getAlgorithm(), getProvider()) : SecureRandom.getInstance(getAlgorithm()); } catch (NoSuchProviderException ex) { throw new NoSuchProviderException("no such secure random provider: " + getProvider()); } catch (NoSuchAlgorithmException ex) { throw new NoSuchAlgorithmException("no such secure random algorithm: " + getAlgorithm()); } }
private SecureRandom createSecureRandom(ContextAware context) throws NoSuchProviderException, NoSuchAlgorithmException { SecureRandom secureRandom = getSecureRandom().createSecureRandom(); context.addInfo("secure random algorithm '" + secureRandom.getAlgorithm() + "' provider '" + secureRandom.getProvider() + "'"); return secureRandom; }