本文整理汇总了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());
}
}