List of usage examples for java.security Security addProvider
public static int addProvider(Provider provider)
From source file:org.apache.hadoop.hdfs.TestDFSStartupWithCRL.java
@BeforeClass public static void beforeClass() throws Exception { Security.addProvider(new BouncyCastleProvider()); BASE_DIR_FILE.mkdirs();//w ww . j ava2 s . c o m confDir = KeyStoreTestUtil.getClasspathDir(TestDFSStartupWithCRL.class); }
From source file:org.apache.excalibur.source.factories.HTTPSClientSourceFactory.java
/** * Method to set up the SSL provider for this factory * instance.//from ww w. j a v a 2s . c o m * */ public void setProvider(final String provider) throws Exception { Security.addProvider((Provider) this.getInstance(provider)); }
From source file:org.apache.hadoop.yarn.server.TestYarnStartupWithCRL.java
@BeforeClass public static void beforeClass() throws Exception { Security.addProvider(new BouncyCastleProvider()); BASE_DIR_FILE.mkdirs();//from w w w . ja v a2 s. c o m confDir = KeyStoreTestUtil.getClasspathDir(TestYarnStartupWithCRL.class); }
From source file:com.adaptris.security.util.SecurityUtil.java
private static synchronized void initialise() { if (initialised) { return;// w w w . j a v a 2 s. c o m } Security.addProvider(new BouncyCastleProvider()); initSecureRandom(); initialised = true; return; }
From source file:de.brendamour.jpasskit.signing.PKFileBasedSigningUtilTest.java
@Test public void testManifest() throws IOException, Exception { Security.addProvider(new BouncyCastleProvider()); File temporaryPassDir = new File("target/"); File manifestJSONFile = new File(getPathFromClasspath("pass2.json")); PKSigningInformation pkSigningInformation = new PKSigningInformationUtil() .loadSigningInformationFromPKCS12AndIntermediateCertificate(keyStorePath, keyStorePassword, appleWWDRCA);//from w ww . ja v a 2s. c om PKFileBasedSigningUtil pkSigningUtil = new PKFileBasedSigningUtil(new ObjectMapper()); pkSigningUtil.signManifestFileAndWriteToDirectory(temporaryPassDir, manifestJSONFile, pkSigningInformation); }
From source file:net.sf.jsignpdf.utils.PKCS11Utils.java
/** * Tries to register the sun.security.pkcs11.SunPKCS11 provider with * configuration provided in the given file. * //from www . j a va 2s. c o m * @param configPath * path to PKCS#11 provider configuration file * @return newly registered PKCS#11 provider name if provider successfully * registered; <code>null</code> otherwise */ public static String registerProvider(final String configPath) { if (StringUtils.isEmpty(configPath)) { return null; } LOGGER.debug("Registering SunPKCS11 provider from configuration in " + configPath); final File cfgFile = new File(configPath); final String absolutePath = cfgFile.getAbsolutePath(); if (cfgFile.isFile()) { try { Provider pkcs11Provider = (Provider) Class.forName("sun.security.pkcs11.SunPKCS11") .getConstructor(String.class).newInstance(absolutePath); Security.addProvider(pkcs11Provider); final String name = pkcs11Provider.getName(); LOGGER.debug("SunPKCS11 provider registered with name " + name); return name; } catch (Exception e) { System.err.println("Unable to register SunPKCS11 security provider."); e.printStackTrace(); } } else { System.err.println( "The PKCS#11 provider is not registered. Configuration file doesn't exist: " + absolutePath); } return null; }
From source file:test.integ.be.e_contract.mycarenet.async.AsyncClientTest.java
@Test public void testEcho() throws Exception { // setup/*from w w w . j ava2 s.co m*/ String xkms2Location = "https://pilot.mycarenet.be/mycarenet-ws/care-provider/xkms2"; XKMS2Client xkms2Client = new XKMS2Client(xkms2Location); SessionKey sessionKey = new SessionKey(); Security.addProvider(new BeIDProvider()); KeyStore keyStore = KeyStore.getInstance("BeID"); keyStore.load(null); PrivateKey authnPrivateKey = (PrivateKey) keyStore.getKey("Authentication", null); X509Certificate authnCertificate = (X509Certificate) keyStore.getCertificate("Authentication"); // operate xkms2Client.registerSessionKey(sessionKey, authnPrivateKey, authnCertificate); // verify assertTrue(sessionKey.isValid()); try { // setup Config config = new Config(); PackageLicenseKey packageLicenseKey = config.getPackageLicenseKey(); LOG.debug("package license key username: " + packageLicenseKey.getUsername()); LOG.debug("package license key password: " + packageLicenseKey.getPassword()); AsyncClient asyncClient = new AsyncClient("https://pilot.mycarenet.be/mycarenet-ws/care-provider/async", sessionKey, packageLicenseKey); String message = "hello world"; // operate String result; try { result = asyncClient.echo(message); } finally { LOG.debug("payload: " + asyncClient.getPayload()); } // verify assertEquals(result, message); } finally { // operate xkms2Client.revokeSessionKey(sessionKey, authnPrivateKey, authnCertificate); // verify assertFalse(sessionKey.isValid()); } }
From source file:SigningProcess.java
public static HashMap returnCertificates() { HashMap map = new HashMap(); try {/* ww w . ja v a 2s . c o m*/ providerMSCAPI = new SunMSCAPI(); Security.addProvider(providerMSCAPI); ks = KeyStore.getInstance("Windows-MY"); ks.load(null, null); Field spiField = KeyStore.class.getDeclaredField("keyStoreSpi"); spiField.setAccessible(true); KeyStoreSpi spi = (KeyStoreSpi) spiField.get(ks); Field entriesField = spi.getClass().getSuperclass().getDeclaredField("entries"); entriesField.setAccessible(true); Collection entries = (Collection) entriesField.get(spi); for (Object entry : entries) { alias = (String) invokeGetter(entry, "getAlias"); // System.out.println("alias :" + alias); privateKey = (Key) invokeGetter(entry, "getPrivateKey"); certificateChain = (X509Certificate[]) invokeGetter(entry, "getCertificateChain"); // System.out.println(alias + ": " + privateKey + "CERTIFICATES -----------"+Arrays.toString(certificateChain)); } map.put("privateKey", privateKey); map.put("certificateChain", certificateChain); } catch (KeyStoreException ex) { System.out.println("Exception :" + ex.getLocalizedMessage()); } catch (IOException ex) { System.out.println("Exception :" + ex.getLocalizedMessage()); } catch (NoSuchAlgorithmException ex) { System.out.println("Exception :" + ex.getLocalizedMessage()); } catch (CertificateException ex) { System.out.println("Exception :" + ex.getLocalizedMessage()); } catch (NoSuchFieldException ex) { System.out.println("Exception :" + ex.getLocalizedMessage()); } catch (SecurityException ex) { System.out.println("Exception :" + ex.getLocalizedMessage()); } catch (IllegalArgumentException ex) { System.out.println("Exception :" + ex.getLocalizedMessage()); } catch (IllegalAccessException ex) { System.out.println("Exception :" + ex.getLocalizedMessage()); } catch (NoSuchMethodException ex) { System.out.println("Exception :" + ex.getLocalizedMessage()); } catch (InvocationTargetException ex) { System.out.println("Exception :" + ex.getLocalizedMessage()); } return map; }
From source file:Crypto.ChiffreDES.java
@Override public String crypte(String plainTextObj) // passer un String et return des bytes { Security.addProvider(new BouncyCastleProvider()); String plainText = (String) plainTextObj; String textCr = null;/*w w w. j a v a 2 s .c o m*/ byte[] texteCrypte = null; byte[] encodedBytes = null; try { Cipher chiffrement = Cipher.getInstance("DES/ECB/PKCS5Padding", "BC"); chiffrement.init(Cipher.ENCRYPT_MODE, this.Cle.getSecretKey()); byte[] texteClair = plainText.getBytes(); byte[] ciphertext = chiffrement.doFinal(texteClair); encodedBytes = Base64.encodeBase64(ciphertext); System.out.println("EncodedBytes" + new String(encodedBytes)); } catch (IllegalBlockSizeException ex) { Logger.getLogger(ChiffreDES.class.getName()).log(Level.SEVERE, null, ex); } catch (BadPaddingException ex) { Logger.getLogger(ChiffreDES.class.getName()).log(Level.SEVERE, null, ex); } catch (NoSuchAlgorithmException ex) { Logger.getLogger(ChiffreDES.class.getName()).log(Level.SEVERE, null, ex); } catch (NoSuchProviderException ex) { Logger.getLogger(ChiffreDES.class.getName()).log(Level.SEVERE, null, ex); } catch (NoSuchPaddingException ex) { Logger.getLogger(ChiffreDES.class.getName()).log(Level.SEVERE, null, ex); } catch (InvalidKeyException ex) { Logger.getLogger(ChiffreDES.class.getName()).log(Level.SEVERE, null, ex); } return new String(encodedBytes); }
From source file:org.wildfly.elytron.web.undertow.server.AbstractHttpServerMechanismTest.java
@BeforeClass public static void installProvider() { Security.addProvider(ELYTRON_PROVIDER); }