本文整理汇总了Java中java.security.Security.removeProvider方法的典型用法代码示例。如果您正苦于以下问题:Java Security.removeProvider方法的具体用法?Java Security.removeProvider怎么用?Java Security.removeProvider使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.security.Security
的用法示例。
在下文中一共展示了Security.removeProvider方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import java.security.Security; //导入方法依赖的package包/类
@Override
public void main(Provider p) throws Exception {
/*
* Use Solaris SPARC 11.2 or later to avoid an intermittent failure
* when running SunPKCS11-Solaris (8044554)
*/
if (p.getName().equals("SunPKCS11-Solaris") &&
props.getProperty("os.name").equals("SunOS") &&
props.getProperty("os.arch").equals("sparcv9") &&
props.getProperty("os.version").compareTo("5.11") <= 0 &&
getDistro().compareTo("11.2") < 0) {
System.out.println("SunPKCS11-Solaris provider requires " +
"Solaris SPARC 11.2 or later, skipping");
return;
}
long start = System.currentTimeMillis();
Providers.setAt(p, 1);
try {
String PROVIDER = p.getName();
String javaHome = props.getProperty("java.home");
String caCerts = javaHome + SEP + "lib" + SEP + "security" + SEP + "cacerts";
KeyStore ks;
try (InputStream in = new FileInputStream(caCerts)) {
ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(in, null);
}
for (Enumeration e = ks.aliases(); e.hasMoreElements(); ) {
String alias = (String)e.nextElement();
if (ks.isCertificateEntry(alias)) {
System.out.println("* Testing " + alias + "...");
X509Certificate cert = (X509Certificate)ks.getCertificate(alias);
PublicKey key = cert.getPublicKey();
String alg = key.getAlgorithm();
if (alg.equals("RSA")) {
System.out.println("Signature algorithm: " + cert.getSigAlgName());
cert.verify(key, PROVIDER);
} else {
System.out.println("Skipping cert with key: " + alg);
}
} else {
System.out.println("Skipping alias " + alias);
}
}
long stop = System.currentTimeMillis();
System.out.println("All tests passed (" + (stop - start) + " ms).");
} finally {
Security.removeProvider(p.getName());
}
}
示例2: addProvider
import java.security.Security; //导入方法依赖的package包/类
/**
* 添加签名,验签,加密算法提供者
*/
private static void addProvider(){
if (Security.getProvider("BC") == null) {
LogUtil.writeLog("add BC provider");
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
} else {
Security.removeProvider("BC"); //解决eclipse调试时tomcat自动重新加载时,BC存在不明原因异常的问题。
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
LogUtil.writeLog("re-add BC provider");
}
printSysInfo();
}
示例3: addProvider
import java.security.Security; //导入方法依赖的package包/类
/**
* 添加签名,验签,加密算法提供者
*/
private static void addProvider(){
if (Security.getProvider("BC") == null) {
log.info("add BC provider");
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
} else {
Security.removeProvider("BC"); //解决eclipse调试时tomcat自动重新加载时,BC存在不明原因异常的问题。
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
log.info("re-add BC provider");
}
printSysInfo();
}
示例4: registerBCProvider
import java.security.Security; //导入方法依赖的package包/类
/**
* Registers Bouncy Castle as first security provider before any other providers
* coming with the java runtime.
* </br>ATS calls this method internally when it is supposed to be needed.
*
* </br></br><b>Note:</b> This is a static operation. All working threads will be affected.
* The method itself is not thread-safe.
*
* </br></br><b>Note:</b> It does not duplicate if already available.
*/
public static void registerBCProvider() {
boolean needToInsert = true;
boolean needToRemove = false;
Provider bcProvider = new BouncyCastleProvider();
Provider[] providers = Security.getProviders();
for (int i = 0; i < providers.length; i++) {
if (providers[i].getName().equalsIgnoreCase(bcProvider.getName())) {
if (i == 0) {
needToInsert = false;
} else {
needToRemove = true;
}
break;
}
}
if (needToInsert) {
if (needToRemove) {
Security.removeProvider(bcProvider.getName());
}
Security.insertProviderAt(bcProvider, 1);
log.info("Bouncy Castle security provider is registered as first in the list of available providers");
}
}
示例5: unregisterBCProvider
import java.security.Security; //导入方法依赖的package包/类
/**
* Unregisters Bouncy Castle security provider
*/
public static void unregisterBCProvider() {
final String bcProviderName = new BouncyCastleProvider().getName();
Provider[] providers = Security.getProviders();
for (int i = 0; i < providers.length; i++) {
if (providers[i].getName().equalsIgnoreCase(bcProviderName)) {
Security.removeProvider(bcProviderName);
log.info("Bouncy Castle security provider is unregistered from the list of available providers");
return;
}
}
}
示例6: SftpClient
import java.security.Security; //导入方法依赖的package包/类
/**
* Constructor
*
*/
public SftpClient() {
super();
// Add BoncyCastle provider as the first one, before any default JRE providers.
// We remove it first, because in case the provider is already present as not-the-first-one,
// the insertion will not do any change
boolean needToInsert = true;
boolean needToRemove = false;
Provider bcProvider = new BouncyCastleProvider();
Provider[] providers = Security.getProviders();
for (int i = 0; i < providers.length; i++) {
if (providers[i].getName().equalsIgnoreCase(bcProvider.getName())) {
if (i == 0) {
needToInsert = false;
} else {
needToRemove = true;
}
break;
}
}
if (needToInsert) {
if (needToRemove) {
Security.removeProvider(bcProvider.getName());
}
Security.insertProviderAt(bcProvider, 1);
}
}
示例7: setAt
import java.security.Security; //导入方法依赖的package包/类
public static void setAt(Provider p, int pos) throws Exception {
if (Security.getProvider(p.getName()) != null) {
Security.removeProvider(p.getName());
}
if (Security.insertProviderAt(p, pos) == -1) {
throw new Exception("cannot setAt");
}
}
示例8: main
import java.security.Security; //导入方法依赖的package包/类
@Override
public void main(Provider p) throws Exception {
if (p.getService("KeyFactory", "EC") == null) {
System.out.println("Provider does not support EC, skipping");
return;
}
Providers.setAt(p, 1);
CipherTest.main(new JSSEFactory(), cmdArgs);
Security.removeProvider(p.getName());
}
示例9: disableSpongyCastleOnLollipop
import java.security.Security; //导入方法依赖的package包/类
public static void disableSpongyCastleOnLollipop() {
if (Build.VERSION.SDK_INT == 21) {
Security.removeProvider(SPONGYCASTLE_PROVIDER.getName());
}
}
示例10: setProvider
import java.security.Security; //导入方法依赖的package包/类
public static void setProvider(Provider provider) {
if (KeyStoreFileManager.provider != null) Security.removeProvider( KeyStoreFileManager.provider.getName());
KeyStoreFileManager.provider = provider;
Security.addProvider( provider);
}
示例11: main
import java.security.Security; //导入方法依赖的package包/类
public static void main(String argv[]) throws Exception {
Security.removeProvider(SUNJCE);
Security.addProvider(new com.sun.crypto.provider.SunJCE());
new TestAESWithProviderChange().run(argv);
}
示例12: main
import java.security.Security; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
if (initSecmod() == false) {
return;
}
if ("sparc".equals(System.getProperty("os.arch")) == false) {
// we have not updated other platforms with the proper NSS libraries yet
System.out.println("Test currently works only on solaris-sparc, skipping");
return;
}
String configName = BASE + SEP + "fips.cfg";
Provider p = getSunPKCS11(configName);
System.out.println(p);
Security.addProvider(p);
Security.removeProvider("SunJSSE");
Provider jsse = new com.sun.net.ssl.internal.ssl.Provider(p);
Security.addProvider(jsse);
System.out.println(jsse.getInfo());
KeyStore ks = KeyStore.getInstance("PKCS11", p);
ks.load(null, "test12".toCharArray());
X509Certificate server = loadCertificate("certs/server.cer");
X509Certificate ca = loadCertificate("certs/ca.cer");
X509Certificate anchor = loadCertificate("certs/anchor.cer");
if (args.length > 1 && "sm".equals(args[0])) {
Policy.setPolicy(Policy.getInstance("JavaPolicy",
new URIParameter(new File(BASE, args[1]).toURI())));
System.setSecurityManager(new SecurityManager());
}
KeyStore trustStore = KeyStore.getInstance("JKS");
trustStore.load(null, null);
trustStore.setCertificateEntry("anchor", anchor);
TrustManagerFactory tmf = TrustManagerFactory.getInstance("PKIX");
tmf.init(trustStore);
X509TrustManager tm = (X509TrustManager)tmf.getTrustManagers()[0];
X509Certificate[] chain = {server, ca, anchor};
tm.checkServerTrusted(chain, "RSA");
System.out.println("OK");
}
示例13: removeProvider
import java.security.Security; //导入方法依赖的package包/类
@After
public void removeProvider() {
Security.removeProvider("Cloud Foundry Container");
}
开发者ID:cloudfoundry,项目名称:java-buildpack-security-provider,代码行数:5,代码来源:CloudFoundryContainerProviderTest.java
示例14: remove
import java.security.Security; //导入方法依赖的package包/类
/**
* Remove this provider and revert the security settings.
*/
public static void remove() {
AccessController.doPrivileged((PrivilegedAction<String>) () -> {
Security.setProperty("securerandom.strongAlgorithms", PREVIOUS_STRONG_ALGO);
return PREVIOUS_STRONG_ALGO;
});
Security.removeProvider(PROVIDER_NAME);
}