/** * Finds the appropriate service implementation and returns an * {@code SpiAndProvider} instance containing a reference to SPI * and its {@code Provider} */ public SpiAndProvider getInstance(String algorithm, Object param) throws NoSuchAlgorithmException { if (algorithm == null) { throw new NoSuchAlgorithmException("Null algorithm name"); } int newCacheVersion = Services.getCacheVersion(); Provider.Service service; ServiceCacheEntry cacheEntry = this.serviceCache; if (cacheEntry != null && cacheEntry.algorithm.equalsIgnoreCase(algorithm) && newCacheVersion == cacheEntry.cacheVersion) { service = cacheEntry.service; } else { if (Services.isEmpty()) { throw notFound(serviceName, algorithm); } String name = this.serviceName + "." + algorithm.toUpperCase(Locale.US); service = Services.getService(name); if (service == null) { throw notFound(serviceName, algorithm); } this.serviceCache = new ServiceCacheEntry(algorithm, newCacheVersion, service); } return new SpiAndProvider(service.newInstance(param), service.getProvider()); }
/** * Constructs a new {@code SecureRandom} that uses the default algorithm. */ public SecureRandom() { super(0); Provider.Service service = Services.getSecureRandomService(); if (service == null) { this.provider = null; this.secureRandomSpi = new SHA1PRNG_SecureRandomImpl(); this.algorithm = "SHA1PRNG"; } else { try { this.provider = service.getProvider(); this.secureRandomSpi = (SecureRandomSpi)service.newInstance(null); this.algorithm = service.getAlgorithm(); } catch (Exception e) { throw new RuntimeException(e); } } }
/** * @return new secure random number generator instance using best fitting service */ Random newRandomNumberGenerator() { if (service != null) { try { return SecureRandom.getInstance(service.getAlgorithm(), service.getProvider()); } catch (NoSuchAlgorithmException nsax) { // this shouldn't happen, because 'detectBestFittingService' has checked for existing provider and // algorithms. } } return new SecureRandom(); } }
/** * Finds the appropriate service implementation and returns an * {@code SpiAndProvider} instance containing a reference to SPI * and its {@code Provider} */ public SpiAndProvider getInstance(String algorithm, Object param) throws NoSuchAlgorithmException { if (algorithm == null) { throw new NoSuchAlgorithmException("Null algorithm name"); } int newCacheVersion = Services.getCacheVersion(); Provider.Service service; ServiceCacheEntry cacheEntry = this.serviceCache; if (cacheEntry != null && cacheEntry.algorithm.equalsIgnoreCase(algorithm) && newCacheVersion == cacheEntry.cacheVersion) { service = cacheEntry.service; } else { if (Services.isEmpty()) { throw notFound(serviceName, algorithm); } String name = this.serviceName + "." + algorithm.toUpperCase(Locale.US); service = Services.getService(name); if (service == null) { throw notFound(serviceName, algorithm); } this.serviceCache = new ServiceCacheEntry(algorithm, newCacheVersion, service); } return new SpiAndProvider(service.newInstance(param), service.getProvider()); }
/** * Finds the appropriate service implementation and returns an * {@code SpiAndProvider} instance containing a reference to SPI * and its {@code Provider} */ public SpiAndProvider getInstance(String algorithm, Object param) throws NoSuchAlgorithmException { if (algorithm == null) { throw new NoSuchAlgorithmException("Null algorithm name"); } int newCacheVersion = Services.getCacheVersion(); Provider.Service service; ServiceCacheEntry cacheEntry = this.serviceCache; if (cacheEntry != null && cacheEntry.algorithm.equalsIgnoreCase(algorithm) && newCacheVersion == cacheEntry.cacheVersion) { service = cacheEntry.service; } else { if (Services.isEmpty()) { throw notFound(serviceName, algorithm); } String name = this.serviceName + "." + algorithm.toUpperCase(Locale.US); service = Services.getService(name); if (service == null) { throw notFound(serviceName, algorithm); } this.serviceCache = new ServiceCacheEntry(algorithm, newCacheVersion, service); } return new SpiAndProvider(service.newInstance(param), service.getProvider()); }
/** * Finds the appropriate service implementation and returns an * {@code SpiAndProvider} instance containing a reference to SPI * and its {@code Provider} */ public SpiAndProvider getInstance(String algorithm, Object param) throws NoSuchAlgorithmException { if (algorithm == null) { throw new NoSuchAlgorithmException("Null algorithm name"); } int newCacheVersion = Services.getCacheVersion(); Provider.Service service; ServiceCacheEntry cacheEntry = this.serviceCache; if (cacheEntry != null && cacheEntry.algorithm.equalsIgnoreCase(algorithm) && newCacheVersion == cacheEntry.cacheVersion) { service = cacheEntry.service; } else { if (Services.isEmpty()) { throw notFound(serviceName, algorithm); } String name = this.serviceName + "." + algorithm.toUpperCase(Locale.US); service = Services.getService(name); if (service == null) { throw notFound(serviceName, algorithm); } this.serviceCache = new ServiceCacheEntry(algorithm, newCacheVersion, service); } return new SpiAndProvider(service.newInstance(param), service.getProvider()); }
/** * Finds the appropriate service implementation and returns an * {@code SpiAndProvider} instance containing a reference to SPI * and its {@code Provider} */ public SpiAndProvider getInstance(String algorithm, Object param) throws NoSuchAlgorithmException { if (algorithm == null) { throw new NoSuchAlgorithmException("Null algorithm name"); } int newCacheVersion = Services.getCacheVersion(); Provider.Service service; ServiceCacheEntry cacheEntry = this.serviceCache; if (cacheEntry != null && cacheEntry.algorithm.equalsIgnoreCase(algorithm) && newCacheVersion == cacheEntry.cacheVersion) { service = cacheEntry.service; } else { if (Services.isEmpty()) { throw notFound(serviceName, algorithm); } String name = this.serviceName + "." + algorithm.toUpperCase(Locale.US); service = Services.getService(name); if (service == null) { throw notFound(serviceName, algorithm); } this.serviceCache = new ServiceCacheEntry(algorithm, newCacheVersion, service); } return new SpiAndProvider(service.newInstance(param), service.getProvider()); }
/** * Constructs a new {@code SecureRandom} that uses the default algorithm. */ public SecureRandom() { super(0); Provider.Service service = Services.getSecureRandomService(); if (service == null) { this.provider = null; this.secureRandomSpi = new SHA1PRNG_SecureRandomImpl(); this.algorithm = "SHA1PRNG"; } else { try { this.provider = service.getProvider(); this.secureRandomSpi = (SecureRandomSpi)service.newInstance(null); this.algorithm = service.getAlgorithm(); } catch (Exception e) { throw new RuntimeException(e); } } }
/** * Constructs a new {@code SecureRandom} that uses the default algorithm. */ public SecureRandom() { super(0); Provider.Service service = Services.getSecureRandomService(); if (service == null) { this.provider = null; this.secureRandomSpi = new SHA1PRNG_SecureRandomImpl(); this.algorithm = "SHA1PRNG"; } else { try { this.provider = service.getProvider(); this.secureRandomSpi = (SecureRandomSpi)service.newInstance(null); this.algorithm = service.getAlgorithm(); } catch (Exception e) { throw new RuntimeException(e); } } }
/** * Constructs a new {@code SecureRandom} that uses the default algorithm. */ public SecureRandom() { super(0); Provider.Service service = Services.getSecureRandomService(); if (service == null) { this.provider = null; this.secureRandomSpi = new SHA1PRNG_SecureRandomImpl(); this.algorithm = "SHA1PRNG"; } else { try { this.provider = service.getProvider(); this.secureRandomSpi = (SecureRandomSpi)service.newInstance(null); this.algorithm = service.getAlgorithm(); } catch (Exception e) { throw new RuntimeException(e); } } }
/** * Constructs a new {@code SecureRandom} that uses the default algorithm. */ public SecureRandom() { super(0); Provider.Service service = Services.getSecureRandomService(); if (service == null) { this.provider = null; this.secureRandomSpi = new SHA1PRNG_SecureRandomImpl(); this.algorithm = "SHA1PRNG"; } else { try { this.provider = service.getProvider(); this.secureRandomSpi = (SecureRandomSpi)service.newInstance(null); this.algorithm = service.getAlgorithm(); } catch (Exception e) { throw new RuntimeException(e); } } }
/** * Constructs a new {@code SecureRandom} that uses the default algorithm. */ public SecureRandom() { super(0); Provider.Service service = Services.getSecureRandomService(); if (service == null) { this.provider = null; this.secureRandomSpi = new SHA1PRNG_SecureRandomImpl(); this.algorithm = "SHA1PRNG"; } else { try { this.provider = service.getProvider(); this.secureRandomSpi = (SecureRandomSpi)service.newInstance(null); this.algorithm = service.getAlgorithm(); } catch (Exception e) { throw new RuntimeException(e); } } }
/** * Constructs a new {@code SecureRandom} that uses the default algorithm. */ public SecureRandom() { super(0); Provider.Service service = Services.getSecureRandomService(); if (service == null) { this.provider = null; this.secureRandomSpi = new SHA1PRNG_SecureRandomImpl(); this.algorithm = "SHA1PRNG"; } else { try { this.provider = service.getProvider(); this.secureRandomSpi = (SecureRandomSpi)service.newInstance(null); this.algorithm = service.getAlgorithm(); } catch (Exception e) { throw new RuntimeException(e); } } }
/** * Find the first provider from the supplier which provides the given service type and algorithm name. * * If a providerName is specified the match will only be tested against providers with the name specified. * * @param providerSupplier the provider supplier (must not be {@code null}) * @param providerName the name of the provider, can be {@code null} * @param serviceType the service type (must not be {@code null}) * @param algorithm the algorithm name (must not be {@code null}) * @return the provider, or {@code null} if none is found */ public static Provider findProvider(Supplier<Provider[]> providerSupplier, String providerName, String serviceType, String algorithm) { final Provider.Service service = findProviderService(providerSupplier, providerName, serviceType, algorithm); return service == null ? null : service.getProvider(); }
/** * Find the first provider from the supplier which provides the given service type and algorithm name. * * If a providerName is specified the match will only be tested against providers with the name specified. * * @param providerSupplier the provider supplier (must not be {@code null}) * @param providerName the name of the provider, can be {@code null} * @param serviceType the service type (must not be {@code null}) * @param algorithm the algorithm name (must not be {@code null}) * @return the provider, or {@code null} if none is found */ public static Provider findProvider(Supplier<Provider[]> providerSupplier, String providerName, String serviceType, String algorithm) { final Provider.Service service = findProviderService(providerSupplier, providerName, serviceType, algorithm); return service == null ? null : service.getProvider(); }
/** * Find the first provider from the supplier which provides the given service type and algorithm name. * * If a providerName is specified the match will only be tested against providers with the name specified. * * @param providerSupplier the provider supplier (must not be {@code null}) * @param providerName the name of the provider, can be {@code null} * @param serviceType the service type (must not be {@code null}) * @param algorithm the algorithm name (must not be {@code null}) * @return the provider, or {@code null} if none is found */ public static Provider findProvider(Supplier<Provider[]> providerSupplier, String providerName, String serviceType, String algorithm) { final Provider.Service service = findProviderService(providerSupplier, providerName, serviceType, algorithm); return service == null ? null : service.getProvider(); }
private static String asString(Service s) { String str = "Provider = " + s.getProvider().getName() + SEP; str += "Type = " + s.getType() + SEP; str += "Algorithm = " + s.getAlgorithm() + SEP; str += "Class = " + s.getClassName(); if (isSignature(s) || isCipher(s) || isKeyAgreement(s)) { str += SEP + "SupportedKeyClasses = " + Arrays.toString(getSupportedKeyClasses(s)); } return str; }
public static Instance getInstance(Service s, Class<?> clazz, Object param) throws NoSuchAlgorithmException { Object instance = s.newInstance(param); checkSuperClass(s, instance.getClass(), clazz); return new Instance(s.getProvider(), instance); }
public static Instance getInstance(Service s, Class<?> clazz) throws NoSuchAlgorithmException { Object instance = s.newInstance(null); checkSuperClass(s, instance.getClass(), clazz); return new Instance(s.getProvider(), instance); }
/** * Find the first provider from the supplier which provides the given service type and algorithm name. * * If a providerName is specified the match will only be tested against providers with the name specified. * * @param providerSupplier the provider supplier (must not be {@code null}) * @param providerName the name of the provider, can be {@code null} * @param serviceType the service type (must not be {@code null}) * @param algorithm the algorithm name (must not be {@code null}) * @return the provider, or {@code null} if none is found */ public static Provider findProvider(Supplier<Provider[]> providerSupplier, String providerName, String serviceType, String algorithm) { final Provider.Service service = findProviderService(providerSupplier, providerName, serviceType, algorithm); return service == null ? null : service.getProvider(); }