當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。