当前位置: 首页>>代码示例>>Java>>正文


Java Security.getProviders方法代码示例

本文整理汇总了Java中java.security.Security.getProviders方法的典型用法代码示例。如果您正苦于以下问题:Java Security.getProviders方法的具体用法?Java Security.getProviders怎么用?Java Security.getProviders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.security.Security的用法示例。


在下文中一共展示了Security.getProviders方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import java.security.Security; //导入方法依赖的package包/类
public static void main(String arg[]) throws Exception{

        boolean failure = false;

        for (Provider p: Security.getProviders()) {
            System.out.print(p.getName() + " ");
            if (p.getVersion() != 10.0d) {
                System.out.println("failed. " + "Version received was " +
                        p.getVersion());
                failure = true;
            } else {
                System.out.println("passed.");
            }
        }

        if (failure) {
            throw new Exception("Provider(s) failed to have the expected " +
                    "version value.");
        }
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:ProviderVersionCheck.java

示例2: ProviderList

import java.security.Security; //导入方法依赖的package包/类
public ProviderList(GSSCaller caller, boolean useNative) {
    this.caller = caller;
    Provider[] provList;
    if (useNative) {
        provList = new Provider[1];
        provList[0] = new SunNativeProvider();
    } else {
        provList = Security.getProviders();
    }

    for (int i = 0; i < provList.length; i++) {
        Provider prov = provList[i];
        try {
            addProviderAtEnd(prov, null);
        } catch (GSSException ge) {
            // Move on to the next provider
            GSSUtil.debug("Error in adding provider " +
                          prov.getName() + ": " + ge);
        }
    } // End of for loop
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:22,代码来源:ProviderList.java

示例3: installSecureRandomProvider

import java.security.Security; //导入方法依赖的package包/类
private void installSecureRandomProvider(Provider provider) {
	Provider[] providers = Security.getProviders("SecureRandom.SHA1PRNG");
	if (providers == null || providers.length == 0
			|| !provider.getClass().equals(providers[0].getClass())) {
		Security.insertProviderAt(provider, 1);
	}
	// Check the new provider is the default when no algorithm is specified
	SecureRandom random = new SecureRandom();
	if (!provider.getClass().equals(random.getProvider().getClass())) {
		throw new SecurityException("Wrong SecureRandom provider: "
				+ random.getProvider().getClass());
	}
	// Check the new provider is the default when SHA1PRNG is specified
	try {
		random = SecureRandom.getInstance("SHA1PRNG");
	} catch (NoSuchAlgorithmException e) {
		throw new SecurityException(e);
	}
	if (!provider.getClass().equals(random.getProvider().getClass())) {
		throw new SecurityException("Wrong SHA1PRNG provider: "
				+ random.getProvider().getClass());
	}
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:24,代码来源:CryptoComponentImpl.java

示例4: run

import java.security.Security; //导入方法依赖的package包/类
public void run() throws Exception {

        Provider[] providers = Security.getProviders();
        for (Provider p: providers) {
            String prvName = p.getName();
            if (prvName.startsWith("SunJCE")
                    || prvName.startsWith("SunPKCS11-Solaris")) {
                try {
                    runTest(p);
                    out.println("Test with provider " + p.getName() + ""
                            + " passed");

                } catch (java.security.KeyStoreException e) {
                    if (prvName.startsWith("SunPKCS11-Solaris")) {
                        out.println("KeyStoreException is expected because "
                                + "PKCS11KeyStore is invalid keystore type.");
                        e.printStackTrace();
                    } else {
                        throw e;
                    }
                }
            }
        }
    }
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:25,代码来源:TestKeyStoreEntry.java

示例5: printProviders

import java.security.Security; //导入方法依赖的package包/类
/**
 * 打jre中印算法提供者列表
 */
private static void printProviders() {
	log.info("Providers List:");
	Provider[] providers = Security.getProviders();
	for (int i = 0; i < providers.length; i++) {
		log.info(i + 1 + "." + providers[i].getName());
	}
}
 
开发者ID:howe,项目名称:nutz-pay,代码行数:11,代码来源:CertUtil.java

示例6: main

import java.security.Security; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    try {
        Provider[] providers1 = Security.getProviders();
        System.out.println("Amount of providers1: " + providers1.length);

        Provider[] providers2 = Security.getProviders(serviceAlgFilter);
        System.out.println("Amount of providers2: " + providers2.length);

        Map<String, String> filter = new HashMap<String, String>();
        filter.put(serviceAlgFilter, "");
        Provider[] providers3 = Security.getProviders(filter);
        System.out.println("Amount of providers3: " + providers3.length);

        Provider[] emptyProv1 = Security.getProviders(emptyServAlgFilter);
        if (emptyProv1 != null) {
            throw new RuntimeException("Empty Filter returned: " +
                emptyProv1.length + " providers");
        }
        System.out.println("emptyProv1 is empty as expected");

        Map<String, String> emptyFilter = new HashMap<String, String>();
        emptyFilter.put(emptyServAlgFilter, "");
        Provider[] emptyProv2 = Security.getProviders(emptyFilter);
        if (emptyProv2 != null) {
            throw new RuntimeException("Empty Filter returned: " +
                emptyProv2.length + " providers");
        }
        System.out.println("emptyProv2 is empty as expected");

    } catch(ExceptionInInitializerError e) {
        e.printStackTrace(System.out);
        throw new RuntimeException("Provider initialization error due to "
                + e.getCause());
    }
    System.out.println("Test passed");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:37,代码来源:GetProviders.java

示例7: 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;
        }
    }
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:17,代码来源:SslUtils.java

示例8: 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);
    }
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:37,代码来源:SftpClient.java

示例9: getFactories

import java.security.Security; //导入方法依赖的package包/类
private static Set<Object> getFactories(String serviceName) {
    HashSet<Object> result = new HashSet<Object>();

    if ((serviceName == null) || (serviceName.length() == 0) ||
        (serviceName.endsWith("."))) {
        return result;
    }

    Provider[] provs = Security.getProviders();
    Object fac;

    for (Provider p : provs) {

        Iterator<Service> iter = p.getServices().iterator();
        while (iter.hasNext()) {
            Service s = iter.next();
            if (s.getType().equals(serviceName)) {
                try {
                    fac = loadFactory(s);
                    if (fac != null) {
                        result.add(fac);
                    }
                } catch (Exception ignore) {
                }
            }
        }
    }
    return Collections.unmodifiableSet(result);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:Sasl.java

示例10: listCiphers

import java.security.Security; //导入方法依赖的package包/类
private static void listCiphers(Queue<String> arguments) {
	for (Provider provider : Security.getProviders()) {
           for (Provider.Service service : provider.getServices()) {
               if (service.getType().equals("Cipher")) {
               	System.out.println("Provider: " + provider.getName() + "  Algorithm: " + service.getAlgorithm());
               }
           }
       }
}
 
开发者ID:ncredinburgh,项目名称:secure-tomcat-datasourcefactory,代码行数:10,代码来源:Main.java

示例11: installLinuxPRNGSecureRandom

import java.security.Security; //导入方法依赖的package包/类
/**
 * Installs a Linux PRNG-backed {@code SecureRandom} implementation as the
 * default. Does nothing if the implementation is already the default or if
 * there is not need to install the implementation.
 *
 * @throws SecurityException if the fix is needed but could not be applied.
 */
private static void installLinuxPRNGSecureRandom() throws SecurityException {
    if (Build.VERSION.SDK_INT > VERSION_CODE_JELLY_BEAN_MR2) {
        // No need to apply the fix
        return;
    }
    // Install a Linux PRNG-based SecureRandom implementation as the
    // default, if not yet installed.
    Provider[] secureRandomProviders = Security.getProviders("SecureRandom.SHA1PRNG");
    if ((secureRandomProviders == null) || (secureRandomProviders.length < 1) || (!LinuxPRNGSecureRandomProvider.class.equals(secureRandomProviders[0].getClass()))) {
        Security.insertProviderAt(new LinuxPRNGSecureRandomProvider(), 1);
    }
    // Assert that new SecureRandom() and
    // SecureRandom.getInstance("SHA1PRNG") return a SecureRandom backed
    // by the Linux PRNG-based SecureRandom implementation.
    SecureRandom rng1 = new SecureRandom();
    if (!LinuxPRNGSecureRandomProvider.class.equals(rng1.getProvider().getClass())) {
        throw new SecurityException("new SecureRandom() backed by wrong Provider: " + rng1.getProvider().getClass());
    }
    SecureRandom rng2;
    try {
        rng2 = SecureRandom.getInstance("SHA1PRNG");
    } catch (NoSuchAlgorithmException e) {
        throw new SecurityException("SHA1PRNG not available", e);
    }
    if (!LinuxPRNGSecureRandomProvider.class.equals(rng2.getProvider().getClass())) {
        throw new SecurityException("SecureRandom.getInstance(\"SHA1PRNG\") backed by wrong" + " Provider: " + rng2.getProvider().getClass());
    }
}
 
开发者ID:akashdeepsingh9988,项目名称:Cybernet-VPN,代码行数:36,代码来源:PRNGFixes.java

示例12: testDefault

import java.security.Security; //导入方法依赖的package包/类
public static void testDefault(PKCS11Test test) throws Exception {
    // run test for default configured PKCS11 providers (if any)

    if ("true".equals(System.getProperty("NO_DEFAULT"))) {
        return;
    }

    Provider[] providers = Security.getProviders();
    for (int i = 0; i < providers.length; i++) {
        Provider p = providers[i];
        if (p.getName().startsWith("SunPKCS11-")) {
            test.premain(p);
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:PKCS11Test.java

示例13: installLinuxPRNGSecureRandom

import java.security.Security; //导入方法依赖的package包/类
/**
 * Installs a Linux PRNG-backed {@code SecureRandom} implementation as the
 * default. Does nothing if the implementation is already the default or if
 * there is not need to install the implementation.
 *
 * @throws SecurityException if the fix is needed but could not be applied.
 */
private static void installLinuxPRNGSecureRandom()
        throws SecurityException {
    if (Build.VERSION.SDK_INT > VERSION_CODE_JELLY_BEAN_MR2) {
        // No need to apply the fix
        return;
    }

    // Install a Linux PRNG-based SecureRandom implementation as the
    // default, if not yet installed.
    Provider[] secureRandomProviders =
            Security.getProviders("SecureRandom.SHA1PRNG");
    if ((secureRandomProviders == null)
            || (secureRandomProviders.length < 1)
            || (!LinuxPRNGSecureRandomProvider.class.equals(
            secureRandomProviders[0].getClass()))) {
        Security.insertProviderAt(new LinuxPRNGSecureRandomProvider(), 1);
    }

    // Assert that new SecureRandom() and
    // SecureRandom.getInstance("SHA1PRNG") return a SecureRandom backed
    // by the Linux PRNG-based SecureRandom implementation.
    SecureRandom rng1 = new SecureRandom();
    if (!LinuxPRNGSecureRandomProvider.class.equals(
            rng1.getProvider().getClass())) {
        throw new SecurityException(
                "new SecureRandom() backed by wrong Provider: "
                        + rng1.getProvider().getClass());
    }

    SecureRandom rng2;
    try {
        rng2 = SecureRandom.getInstance("SHA1PRNG");
    } catch (NoSuchAlgorithmException e) {
        throw new SecurityException("SHA1PRNG not available", e);
    }
    if (!LinuxPRNGSecureRandomProvider.class.equals(
            rng2.getProvider().getClass())) {
        throw new SecurityException(
                "SecureRandom.getInstance(\"SHA1PRNG\") backed by wrong"
                        + " Provider: " + rng2.getProvider().getClass());
    }
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:50,代码来源:PRNGFixes.java

示例14: getFactories

import java.security.Security; //导入方法依赖的package包/类
private static Set<Object> getFactories(String serviceName) {
    HashSet<Object> result = new HashSet<Object>();

    if ((serviceName == null) || (serviceName.length() == 0) ||
        (serviceName.endsWith("."))) {
        return result;
    }


    Provider[] providers = Security.getProviders();
    HashSet<String> classes = new HashSet<String>();
    Object fac;

    for (int i = 0; i < providers.length; i++) {
        classes.clear();

        // Check the keys for each provider.
        for (Enumeration<Object> e = providers[i].keys(); e.hasMoreElements(); ) {
            String currentKey = (String)e.nextElement();
            if (currentKey.startsWith(serviceName)) {
                // We should skip the currentKey if it contains a
                // whitespace. The reason is: such an entry in the
                // provider property contains attributes for the
                // implementation of an algorithm. We are only interested
                // in entries which lead to the implementation
                // classes.
                if (currentKey.indexOf(" ") < 0) {
                    String className = providers[i].getProperty(currentKey);
                    if (!classes.contains(className)) {
                        classes.add(className);
                        try {
                            fac = loadFactory(providers[i], className);
                            if (fac != null) {
                                result.add(fac);
                            }
                        }catch (Exception ignore) {
                        }
                    }
                }
            }
        }
    }
    return Collections.unmodifiableSet(result);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:45,代码来源:Sasl.java

示例15: getInstance

import java.security.Security; //导入方法依赖的package包/类
/**
 * Returns a <code>KeyInfoFactory</code> that supports the
 * specified XML processing mechanism and representation type (ex: "DOM").
 *
 * <p>This method uses the standard JCA provider lookup mechanism to
 * locate and instantiate a <code>KeyInfoFactory</code> implementation of
 * the desired mechanism type. It traverses the list of registered security
 * <code>Provider</code>s, starting with the most preferred
 * <code>Provider</code>. A new <code>KeyInfoFactory</code> object
 * from the first <code>Provider</code> that supports the specified
 * mechanism is returned.
 *
 * <p> Note that the list of registered providers may be retrieved via
 * the {@link Security#getProviders() Security.getProviders()} method.
 *
 * @implNote
 * The JDK Reference Implementation additionally uses the
 * {@code jdk.security.provider.preferred}
 * {@link Security#getProperty(String) Security} property to determine
 * the preferred provider order for the specified algorithm. This
 * may be different than the order of providers returned by
 * {@link Security#getProviders() Security.getProviders()}.
 *
 * @param mechanismType the type of the XML processing mechanism and
 *    representation.  See the <a href=
 *    "{@docRoot}/../specs/security/standard-names.html#xml-signature-xmlsignaturefactorykeyinfofactorytransformservice-mechanisms">
 *    Java Security Standard Algorithm Names</a> document
 * for more information.
 * @return a new <code>KeyInfoFactory</code>
 * @throws NullPointerException if <code>mechanismType</code> is
 *    <code>null</code>
 * @throws NoSuchMechanismException if no <code>Provider</code> supports a
 *    <code>KeyInfoFactory</code> implementation for the specified mechanism
 * @see Provider
 */
public static KeyInfoFactory getInstance(String mechanismType) {
    if (mechanismType == null) {
        throw new NullPointerException("mechanismType cannot be null");
    }
    Provider[] provs = Security.getProviders();
    for (Provider p : provs) {
        Service s = p.getService("KeyInfoFactory", mechanismType);
        if (s != null) {
            Object obj = null;
            try {
                obj = s.newInstance(null);
            } catch (NoSuchAlgorithmException nsae) {
                throw new NoSuchMechanismException(nsae);
            }
            if (obj instanceof KeyInfoFactory) {
                KeyInfoFactory factory = (KeyInfoFactory) obj;
                factory.mechanismType = mechanismType;
                factory.provider = p;
                return factory;
            }
        }
    }
    throw new NoSuchMechanismException
        ("Mechanism " + mechanismType + " not available");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:61,代码来源:KeyInfoFactory.java


注:本文中的java.security.Security.getProviders方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。