List of usage examples for org.bouncycastle.jce.provider BouncyCastleProvider BouncyCastleProvider
public BouncyCastleProvider()
From source file:at.peppol.commons.security.KeyStoreUtilsTest.java
License:Mozilla Public License
@BeforeClass public static void init() { Security.addProvider(new BouncyCastleProvider()); }
From source file:at.tugraz.ist.akm.keystore.ApplicationKeyStore.java
License:Apache License
private void createNewCertificate() throws InvalidKeyException, SecurityException, SignatureException, NoSuchAlgorithmException, CertificateEncodingException, IllegalStateException, NoSuchProviderException { Security.addProvider(new BouncyCastleProvider()); X509V3CertificateGenerator certGenerator = new X509V3CertificateGenerator(); certGenerator.setSerialNumber(BigInteger.valueOf(Math.abs(mRandom.nextInt() + 1))); certGenerator.setIssuerDN(new X500Principal(CertificateDefaultAttributes.ISSUER)); certGenerator.setSubjectDN(new X500Principal(CertificateDefaultAttributes.SUBJECT)); certGenerator.setNotBefore(new Date( System.currentTimeMillis() - CertificateDefaultAttributes.VALID_DURATION_BEFORE_NOW_MILLISECONDS)); certGenerator.setNotAfter(new Date( System.currentTimeMillis() + CertificateDefaultAttributes.VALID_DURATION_FROM_NOW_MILLISECONDS)); KeyPairGenerator keyGenerator = KeyPairGenerator .getInstance(CertificateDefaultAttributes.KEYPAIR_GENERATOR); keyGenerator.initialize(CertificateDefaultAttributes.KEYPAIR_LENGTH_BITS); KeyPair newKeyPair = keyGenerator.generateKeyPair(); certGenerator.setPublicKey(newKeyPair.getPublic()); certGenerator.setSignatureAlgorithm(CertificateDefaultAttributes.ENCRYPTION_ALGORITHM); X509Certificate newCertificate = certGenerator.generate(newKeyPair.getPrivate()); mCertificate = newCertificate;//from w ww . j ava 2 s.c o m mKeyPair = newKeyPair; }
From source file:ataraxis.crypt.AESKeyCreator.java
License:Open Source License
/** * Create a symetric SecretKey based on the AES Algorithm. * @return the created SecretKey//www .j ava 2s .c o m * @throws NoSuchAlgorithmException if the Algorithm does not exist * @throws NoSuchProviderException if the Provider does not exist * @throws NotImplementedException if the method is not implemented * @see ataraxis.crypt.SecretKeyCreator */ public final SecretKey createSecretKey() throws NoSuchAlgorithmException, NoSuchProviderException, NotImplementedException { LOGGER.debug("createSecretKey() - start"); LOGGER.debug("Size of AES-Key: " + KEY_SIZE); Security.addProvider(new BouncyCastleProvider()); final KeyGenerator generator = KeyGenerator.getInstance("AES", "BC"); generator.init(KEY_SIZE); final SecretKey returnSecretKey = generator.generateKey(); LOGGER.debug("createSecretKey() - end"); return returnSecretKey; }
From source file:ataraxis.crypt.AtaraxisCrypter.java
License:Open Source License
/** * AtaraxisCrypter with the keyStorePath as KeyStore, a * KeyStore password and a boolean for creating a KeyStore. * /* w ww .ja v a2s . c om*/ * Needed Directories for the KeyStore will be createt, if this is allowed. * * @param keyStoreFile Path and File for the KeyStore * @param keyStorePassword Password for the KeyStore * @param createKS true if KeyStore should be created, false otherwise * @throws IOException by errors with the I/O or wrong Password * @throws KeyStoreException by errors with the KeyStore * @throws JurisdictionPolicyError if the PolicyFile ist not unrestricted enough */ public AtaraxisCrypter(File keyStoreFile, char[] keyStorePassword, boolean createKS) throws IOException, KeyStoreException { LOGGER.debug("AtaraxisCrypter(String, String, boolean) - start"); LOGGER.debug("Create " + keyStoreFile.getAbsolutePath() + "? " + createKS); Security.addProvider(new BouncyCastleProvider()); m_props = new Properties(); //m_props.load(new FileInputStream(CONFIG_DIR + "/" + PROPS_FILE)); File defaultProperties = new File(CONFIG_DIR + "/" + PROPS_FILE); String pathSystemProperties = System.getProperty("ATARAXIS_PROPERTIES_FILE", ""); if (pathSystemProperties.length() > 0) { File propertiesFromSystem = new File(pathSystemProperties); if (propertiesFromSystem.exists()) { m_props.load(new FileInputStream(propertiesFromSystem)); } } else if (defaultProperties.exists()) { m_props.load(new FileInputStream(defaultProperties)); } m_keyAlias = m_props.getProperty("ATARAXIS.KEY_ALIAS", "ataraxisMainKey"); m_keyPassword = m_props.getProperty("ATARAXIS.KEY_PW", "sqHo4m"); final String kshClass = m_props.getProperty("ATARAXIS.KEYSTORE_CLASS", "ataraxis.crypt.UBERKeyStoreHandler"); final String ksCreator = m_props.getProperty("ATARAXIS.KEYSTORE_CREATOR_CLASS", "ataraxis.crypt.UBERKeyStoreCreator"); if (createKS) { if (!keyStoreFile.exists()) { final File keyStoreDir = new File(keyStoreFile.getParent()); LOGGER.debug("Create directory " + keyStoreDir.getAbsolutePath()); keyStoreDir.mkdirs(); } else { throw new KeyStoreException("KS already exists"); } } // Always use AES to encrypt/decrypt final SecretKeyCreator kh = new AESKeyCreator(); if (keyStoreFile.exists() && keyStoreFile.canRead()) { LOGGER.debug("KeyStore exist an is readable"); m_keyStoreHandler = getKeyStoreHandler(kshClass, keyStoreFile, keyStorePassword, kh); } else if (keyStoreFile.exists() && !keyStoreFile.canRead()) { LOGGER.error("Access denied on KeyStore by Filesystem"); throw new KeyStoreException("Access denied on KeyStore by Filesystem"); } else if (!keyStoreFile.exists() && createKS) { LOGGER.debug("KeyStore does not exist and creation is allowed"); createKeyStore(ksCreator, keyStoreFile, keyStorePassword); m_keyStoreHandler = getKeyStoreHandler(kshClass, keyStoreFile, keyStorePassword, kh); } else { LOGGER.error("KeyStore does not exist and creation is NOT allowed"); throw new KeyStoreException("KeyStore does not exist an creation is not allowed!"); } LOGGER.debug("AtaraxisCrypter(String, boolean) - end"); }
From source file:ataraxis.crypt.RSAKeyCreator.java
License:Open Source License
/** * Create a asymmetric KeyPair based on the RSA Algorithm. * //from www. ja v a 2 s . c om * @return the created SecretKey * @throws NoSuchAlgorithmException if the Algorithm does not exist * @throws NoSuchProviderException if the Provider does not exist * @see ataraxis.crypt.SecretKeyCreator */ public final KeyPair createKeyPair() throws NoSuchAlgorithmException, NoSuchProviderException { LOGGER.debug("createKeyPair() - start"); LOGGER.debug("Size of RSA-Key: " + KEY_SIZE); Security.addProvider(new BouncyCastleProvider()); KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA", "BC"); generator.initialize(KEY_SIZE); KeyPair returnKeyPair = generator.generateKeyPair(); LOGGER.debug("createKeyPair() - end"); return returnKeyPair; }
From source file:ataraxis.crypt.UBERKeyStoreCreator.java
License:Open Source License
/** * UBERKeyStoreCreator create a UBER KeyStore at the FileSystem-Path * with the submitted password.//from www. j a v a 2 s . c o m * * @param keyStoreFile FileSystemPath to the KeyStore * @param keyStorePassword the password for the Keystore * @return the created and to disk saved KeyStore * @throws KeyStoreException by errors with the KeyStore creation * @throws NoSuchProviderException if the Provider is missing * @throws NoSuchAlgorithmException is the Algorithm is missing */ public final KeyStore createKeyStore(File keyStoreFile, char[] keyStorePassword) throws KeyStoreException, NoSuchProviderException, NoSuchAlgorithmException { LOGGER.debug("createKeyStore(String, String) - start"); Security.addProvider(new BouncyCastleProvider()); KeyStore ksUBER = KeyStore.getInstance("UBER", "BC"); try { // Load empty KeyStore ksUBER.load(null, keyStorePassword); // Save Keystore FileOutputStream fos; fos = new FileOutputStream(keyStoreFile); ksUBER.store(fos, keyStorePassword); fos.close(); } catch (FileNotFoundException e) { LOGGER.error("Error on FileHandling", e); throw new KeyStoreException("Error on FileHandling"); } catch (CertificateException e) { LOGGER.error("Certificate Error on KeyStore", e); throw new KeyStoreException("Certificate Error on KeyStore"); } catch (IOException e) { LOGGER.error("IO Error on writing the KeyStore", e); throw new KeyStoreException("IO Error on writing the KeyStore"); } LOGGER.debug("createKeyStore(String, String) - end"); return ksUBER; }
From source file:ataraxis.crypt.UBERKeyStoreHandler.java
License:Open Source License
/** * Constructor for the UBERKeyStoreHandler with a KeyStorePath and * a KeyStorePassword.//from w w w.j a va2 s . c o m * * @param keyStorePath FileSystemPath to the existing KeyStore * @param keyStorePassword the Password for the KeyStore * @throws KeyStoreException by errors with the KeyStore * @throws NoSuchProviderException if the Provider is missing */ public UBERKeyStoreHandler(File keyStoreFile, char[] keyStorePassword) throws KeyStoreException, NoSuchProviderException { LOGGER.debug("UBERKeyStoreHandler(String, String) - start"); Security.addProvider(new BouncyCastleProvider()); KeyStore uberkeyStore = KeyStore.getInstance("UBER", "BC"); LOGGER.debug("KeyStore Path: " + keyStoreFile.getAbsolutePath()); FileInputStream fis = null; try { fis = new FileInputStream(keyStoreFile); uberkeyStore.load(fis, keyStorePassword); super.setKeyStore(uberkeyStore); super.setKeyStorePath(keyStoreFile.getAbsolutePath()); super.changePassword(null, keyStorePassword); store(); } catch (FileNotFoundException e) { LOGGER.error("KeyStore File not found!", e); throw new KeyStoreException("KeyStore File not found!"); } catch (CertificateException e) { LOGGER.error("Error on Certificate", e); throw new KeyStoreException("Error on Certificate"); } catch (IOException e) { LOGGER.error("IO Error on loading the KeyStore " + e.getMessage()); throw new KeyStoreException("IO Error on loading the KeyStore"); } catch (NoSuchAlgorithmException e) { LOGGER.error("Algorithm of KeyStore does not exist!", e); throw new KeyStoreException("Algorithm of KeyStore does not exist!"); } finally { try { if (fis != null) { fis.close(); } } catch (IOException e) { LOGGER.error("IOException", e); } } LOGGER.debug("UBERKeyStoreHandler(String, String) - end"); }
From source file:be.fedict.eid.dss.model.mbean.DigitalSignatureServiceMBean.java
License:Open Source License
private void registerBouncyCastle() { Provider provider = Security.getProvider(BouncyCastleProvider.PROVIDER_NAME); if (null != provider) { LOG.debug("we don't register BouncyCastle"); return;// w ww . ja v a2s .c om } this.managedBouncyCastleProvider = new BouncyCastleProvider(); LOG.debug("we register BouncyCastle"); if (-1 == Security.addProvider(this.managedBouncyCastleProvider)) { LOG.fatal("could not register BouncyCastle"); } }
From source file:be.fedict.eid.idp.mbean.IdentityProviderMBean.java
License:Open Source License
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 w w . j av a 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:be.fedict.eid.pkira.blm.model.contracthandler.services.SignatureVerificationBeanTest.java
License:Open Source License
private SignatureInfo createSignatureInfo() { try {/* w w w . java2 s . c om*/ InputStream input = SignatureVerificationBeanTest.class.getClassLoader() .getResourceAsStream("aca-it.be.crt"); CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509", new BouncyCastleProvider()); X509Certificate certificate = (X509Certificate) certificateFactory.generateCertificate(input); return new SignatureInfo(certificate, new Date(), ""); } catch (Exception e) { fail("Cannot create signature info.", e); return null; } }