Example usage for java.security Security addProvider

List of usage examples for java.security Security addProvider

Introduction

In this page you can find the example usage for java.security Security addProvider.

Prototype

public static int addProvider(Provider provider) 

Source Link

Document

Adds a provider to the next position available.

Usage

From source file:org.jevis.commons.driver.DataSourceHelper.java

static public void doTrustToCertificates() throws Exception {
    Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
    TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
        public X509Certificate[] getAcceptedIssuers() {
            return null;
        }//from   w  ww  . ja v  a 2s.  c om

        public void checkServerTrusted(X509Certificate[] certs, String authType) throws CertificateException {
            return;
        }

        public void checkClientTrusted(X509Certificate[] certs, String authType) throws CertificateException {
            return;
        }
    } };

    SSLContext sc = SSLContext.getInstance("SSL");
    sc.init(null, trustAllCerts, new SecureRandom());
    HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
    HostnameVerifier hv = new HostnameVerifier() {
        public boolean verify(String urlHostName, SSLSession session) {
            if (!urlHostName.equalsIgnoreCase(session.getPeerHost())) {
                System.out.println("Warning: URL host '" + urlHostName + "' is different to SSLSession host '"
                        + session.getPeerHost() + "'.");
            }
            return true;
        }
    };
    HttpsURLConnection.setDefaultHostnameVerifier(hv);
}

From source file:org.latticesoft.util.common.CryptoHelper.java

public void init() {
    if (this.provider != null) {
        Security.addProvider(provider);
    }
    this.generateKeyPair();
}

From source file:de.brendamour.jpasskit.signing.PKSigningUtilTest.java

public void testManifest() throws IOException, Exception {

    Security.addProvider(new BouncyCastleProvider());
    File temporaryPassDir = new File("/Users/patrice/Documents/bitzeche/Projects/passkit/");
    File manifestJSONFile = new File(
            "/Users/patrice/Downloads/passbook/Passes/BoardingPass.zip Folder/manifest.json");

    PKSigningInformation pkSigningInformation = PKSigningUtil
            .loadSigningInformationFromPKCS12FileAndIntermediateCertificateFile(keyStorePath, keyStorePassword,
                    appleWWDRCA);/*from   w ww .  ja va2s  .  c  o m*/
    PKSigningUtil.signManifestFile(temporaryPassDir, manifestJSONFile, pkSigningInformation);
}

From source file:Crypto.ChiffreDES.java

@Override
public void init(Cle k) {
    Security.addProvider(new BouncyCastleProvider());
    this.Cle = (CleDES) k;
}

From source file:test.integ.be.e_contract.mycarenet.etee.SealerTest.java

@Before
public void setUp() throws Exception {
    this.config = new Config();
    Security.addProvider(new BouncyCastleProvider());
}

From source file:test.integ.be.fedict.hsm.PKCS11Test.java

@Test
public void testEToken() throws Exception {
    File tmpConfigFile = File.createTempFile("pkcs11-", ".conf");
    tmpConfigFile.deleteOnExit();//w w w.j a va2  s.c  o m
    PrintWriter configWriter = new PrintWriter(new FileOutputStream(tmpConfigFile));
    configWriter.println("name=test");
    configWriter.println("library=/usr/lib/libeTPkcs11.so");
    configWriter.println("slotListIndex=0");
    configWriter.close();
    SunPKCS11 sunPKCS11 = new SunPKCS11(tmpConfigFile.getAbsolutePath());
    Security.addProvider(sunPKCS11);

    Security.removeProvider(sunPKCS11.getName());
    sunPKCS11 = new SunPKCS11(tmpConfigFile.getAbsolutePath());
    Security.addProvider(sunPKCS11);

    Security.removeProvider(sunPKCS11.getName());
    sunPKCS11 = new SunPKCS11(tmpConfigFile.getAbsolutePath());
    Security.addProvider(sunPKCS11);

    Security.removeProvider(sunPKCS11.getName());
    sunPKCS11 = new SunPKCS11(tmpConfigFile.getAbsolutePath());
    Security.addProvider(sunPKCS11);

    Security.removeProvider(sunPKCS11.getName());
    sunPKCS11 = new SunPKCS11(tmpConfigFile.getAbsolutePath());
    Security.addProvider(sunPKCS11);

    KeyStore keyStore = KeyStore.getInstance("PKCS11", sunPKCS11);
    keyStore.load(null, "HSMProxy1234".toCharArray());
    Enumeration<String> aliasesEnum = keyStore.aliases();
    String alias = aliasesEnum.nextElement();

    PrivateKey privateKey = (PrivateKey) keyStore.getKey(alias, "HSMProxy1234".toCharArray());

    final int TEST_COUNT = 50;
    int count = TEST_COUNT;
    while (count > 0) {
        Signature signature = Signature.getInstance("SHA1withRSA");
        signature.initSign(privateKey);
        signature.update("to be signed".getBytes());
        signature.sign();
        count--;
    }
}

From source file:CA.InternalCA.java

public InternalCA() {
    // initialize BouncyCastle
    Security.addProvider(new BouncyCastleProvider());
    LOG.info("Initialized BouncyCastle...");
}

From source file:com.premiumminds.billy.france.util.KeyGenerator.java

/**
 * Generates the {@link PrivateKey} and {@link PublicKey} based on the
 * {@link PrivateKey} location.//from w  w w  .  j  a v a 2 s.c  om
 *
 * @param privateKeyPath
 */
public KeyGenerator(String privateKeyPath) {
    if (Security.getProvider("BC") == null) {
        Security.addProvider(new BouncyCastleProvider());
    }
    this.privateKeyPath = privateKeyPath;
}

From source file:be.fedict.eid.idp.mbean.IdentityProviderMBean.java

public void start() throws Exception {
    LOG.debug("start");
    Provider provider = Security.getProvider(BouncyCastleProvider.PROVIDER_NAME);
    if (null != provider) {
        LOG.debug("we don't register BouncyCastle");
        return;/*from   w  ww . java  2s .c  om*/
    }
    this.managedProvider = new BouncyCastleProvider();
    LOG.debug("we register BouncyCastle");
    if (-1 == Security.addProvider(this.managedProvider)) {
        LOG.fatal("could not register BouncyCastle");
    }
}

From source file:com.POLIS.licensing.frontend.AnnotationEnabledFrontendTest.java

@BeforeClass
public static void setUpClass() {
    Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
}