當前位置: 首頁>>代碼示例>>Java>>正文


Java Security.insertProviderAt方法代碼示例

本文整理匯總了Java中java.security.Security.insertProviderAt方法的典型用法代碼示例。如果您正苦於以下問題:Java Security.insertProviderAt方法的具體用法?Java Security.insertProviderAt怎麽用?Java Security.insertProviderAt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.security.Security的用法示例。


在下文中一共展示了Security.insertProviderAt方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: client

import java.security.Security; //導入方法依賴的package包/類
public static void client(int testPort,
        String testProtocols, String testCipher,
        String... exception) throws Exception {
    String expectedException = exception.length >= 1
            ? exception[0] : null;
    out.println("=========================================");
    out.println(" Testing - https://" + LOCAL_IP + ":" + testPort);
    out.println(" Testing - Protocol : " + testProtocols);
    out.println(" Testing - Cipher : " + testCipher);
    Provider p = new sun.security.ec.SunEC();
    Security.insertProviderAt(p, 1);
    try {
        CipherTestUtils.main(new JSSEFactory(LOCAL_IP,
                testPort, testProtocols,
                testCipher, "client JSSE"),
                "client", expectedException);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:21,代碼來源:TestJSSE.java

示例2: 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

示例3: server

import java.security.Security; //導入方法依賴的package包/類
public static void server(String testProtocol, String testCipher,
        int testPort,
        String... exception) throws Exception {
    String expectedException = exception.length >= 1
            ? exception[0] : null;
    out.println(" This is Server");
    out.println(" Testing Protocol: " + testProtocol);
    out.println(" Testing Cipher: " + testCipher);
    out.println(" Testing Port: " + testPort);
    Provider p = new sun.security.ec.SunEC();
    Security.insertProviderAt(p, 1);
    try {
        CipherTestUtils.main(new JSSEFactory(null, testPort,
                testProtocol, testCipher, "Server JSSE"),
                "Server", expectedException);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:20,代碼來源:TestJSSE.java

示例4: main

import java.security.Security; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
    boolean legacy = args[0].equals("2");
    Security.addProvider(new TestProvider("Test1"));
    Security.insertProviderAt(new TestProvider("Test2"), 1);
    try {
        Security.addProvider(new TestProvider("Test3"));
        if (legacy) {
            throw new Exception("Expected SecurityException");
        }
    } catch (SecurityException se) {
        if (!legacy) {
            throw se;
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:16,代碼來源:AddProvider.java

示例5: 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");
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:9,代碼來源:Providers.java

示例6: 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");
    }
}
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:39,代碼來源:SslUtils.java

示例7: 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

示例8: loadProvider

import java.security.Security; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public void loadProvider(String providerClassName)
        throws ClassNotFoundException, IllegalAccessException, InstantiationException {
    Class providerClass = Class.forName(providerClassName);
    Provider provider = (Provider) providerClass.newInstance();
    Security.insertProviderAt(provider, 1);
}
 
開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:8,代碼來源:ZipSigner.java

示例9: main

import java.security.Security; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
    // Try to register a JCE provider from property sun.security.mscapi.testprovider in the first slot
    // otherwise register a dummy provider which would provoke the issue of bug 8139436
    boolean providerPrepended = false;
    String testprovider = System.getProperty("sun.security.mscapi.testprovider");
    if (testprovider != null && !testprovider.isEmpty()) {
        try {
            System.out.println("Trying to prepend external JCE provider " + testprovider);
            Class<?> providerclass = Class.forName(testprovider);
            Object provider = providerclass.newInstance();
            Security.insertProviderAt((Provider)provider, 1);
        } catch (Exception e) {
            System.out.println("Could not load JCE provider " + testprovider +". Exception is:");
            e.printStackTrace(System.out);
        }
        providerPrepended = true;
        System.out.println("Sucessfully prepended JCE provider " + testprovider);
    }
    if (!providerPrepended) {
        System.out.println("Trying to prepend dummy JCE provider");
        Security.insertProviderAt(new TestProvider(), 1);
        System.out.println("Sucessfully prepended dummy JCE provider");
    }

    // load Windows-ROOT KeyStore
    KeyStore keyStore = KeyStore.getInstance("Windows-ROOT", "SunMSCAPI");
    keyStore.load(null, null);

    // iterate KeyStore
    Enumeration<String> aliases = keyStore.aliases();
    while (aliases.hasMoreElements()) {
        String alias = aliases.nextElement();
        System.out.print("Reading certificate for alias: " + alias + "...");
        keyStore.getCertificate(alias);
        System.out.println(" done.");
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:38,代碼來源:IterateWindowsRootStore.java

示例10: AbstractRSSTest

import java.security.Security; //導入方法依賴的package包/類
public AbstractRSSTest(String algorithm, Provider provider, KeyPair keyPair) {
    Security.insertProviderAt(provider, 1);
    this.algorithm = algorithm;
    this.providerName = provider.getName();
    this.provider = provider;
    AbstractRSSTest.keyPair = keyPair;
}
 
開發者ID:woefe,項目名稱:xmlrss,代碼行數:8,代碼來源:AbstractRSSTest.java

示例11: testGetInstanceFromSpecificProviderObject

import java.security.Security; //導入方法依賴的package包/類
@Test
public void testGetInstanceFromSpecificProviderObject() throws Exception {
    Security.insertProviderAt(new WPProvider(), 1);
    RedactableSignature rss = RedactableSignature.getInstance(algorithm, provider);
    assertEquals(algorithm, rss.getAlgorithm());
}
 
開發者ID:woefe,項目名稱:xmlrss,代碼行數:7,代碼來源:AbstractRSSTest.java

示例12: 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:privacyidea,項目名稱:privacyidea-authenticator,代碼行數:50,代碼來源:PRNGFixes.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:CableIM,項目名稱:Cable-Android,代碼行數:50,代碼來源:PRNGFixes.java

示例14: addProvider

import java.security.Security; //導入方法依賴的package包/類
@Before
public void addProvider() {
    Security.insertProviderAt(new CloudFoundryContainerProvider(), 2);
}
 
開發者ID:cloudfoundry,項目名稱:java-buildpack-security-provider,代碼行數:5,代碼來源:CloudFoundryContainerProviderTest.java

示例15: tryInstallLinuxPRNGSecureRandom

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 tryInstallLinuxPRNGSecureRandom()
        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:marius-bardan,項目名稱:encryptedprefs,代碼行數:50,代碼來源:SecureRandomFix.java


注:本文中的java.security.Security.insertProviderAt方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。