本文整理匯總了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);
}
}
示例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());
}
}
示例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);
}
}
示例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;
}
}
}
示例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");
}
}
示例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");
}
}
示例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);
}
}
示例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);
}
示例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.");
}
}
示例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;
}
示例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());
}
示例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());
}
}
示例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());
}
}
示例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());
}
}