All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.polaris.core.crypto.ICryptoProviderLoader Maven / Gradle / Ivy

There is a newer version: 3.2.1
Show newest version
package io.polaris.core.crypto;

import io.polaris.core.service.Service;
import io.polaris.core.service.ServiceLoader;
import org.slf4j.LoggerFactory;

import java.security.Provider;
import java.security.Security;

/**
 * @author Qt
 * @since 1.8
 */
public interface ICryptoProviderLoader {

	Provider provider();

	default int position() {
		return Integer.MAX_VALUE;
	}

	public static void loadProviders() {
		try {
			ServiceLoader serviceLoader = ServiceLoader.of(ICryptoProviderLoader.class);
			for (Service service : serviceLoader) {
				try {
					ICryptoProviderLoader providerLoader = service.getSingleton();
					Security.insertProviderAt(providerLoader.provider(), providerLoader.position());
				} catch (Throwable e) {
					LoggerFactory.getLogger(ICryptoProviderLoader.class).error("", e);
				}
			}
		} catch (Throwable e) {
			LoggerFactory.getLogger(ICryptoProviderLoader.class).error("", e);
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy