List of usage examples for org.bouncycastle.jce.provider BouncyCastleProvider BouncyCastleProvider
public BouncyCastleProvider()
From source file:de.fraunhofer.fokus.openeid.pace.test.TerminalAuthenticationProtocolTest.java
License:Open Source License
@BeforeClass public static void init() throws NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException { Security.addProvider(new BouncyCastleProvider()); ECGenParameterSpec ecSpec = new ECGenParameterSpec("BrainpoolP256r1"); KeyPairGenerator g = KeyPairGenerator.getInstance("ECDSA", "BC"); g.initialize(ecSpec, new SecureRandom()); KeyPair pair = g.generateKeyPair(); privateKey = pair.getPrivate();//from www .j ava 2 s . c o m publicKey = pair.getPublic(); }
From source file:de.jtheuer.diki.lib.pgp.PGPHandler.java
License:Open Source License
/** * Creates a new PGPHandler which is not very usable. This constructor is intedded to be used in * JUnit tests and subclasses//from w w w. j a v a 2 s . c o m */ protected PGPHandler() { /* add security provider for PGP keys */ Security.addProvider(new BouncyCastleProvider()); }
From source file:de.jtheuer.diki.lib.pgp.PGPHandler.java
License:Open Source License
/** * Called by the constructor normally: Stores all necessary keys in the class fields. * @param key//from w ww . j a v a 2 s.c om * @param passphrase * @param identity a {@link Provider} * @throws NoSuchProviderException * @throws PGPException */ protected void init(PGPSecretKey key, char[] passphrase, String identity) throws NoSuchProviderException, PGPException { this.secretkey = key; this.privatekey = secretkey.extractPrivateKey(passphrase, new BouncyCastleProvider()); this.publickey = secretkey.getPublicKey(); this.identity = identity; }
From source file:de.jtheuer.diki.lib.pgp.PGPHandler.java
License:Open Source License
/** * @param input a BASE64 encoded {@link InputStream} * @param output/* w w w. ja va2 s. c om*/ * @throws IOException * @throws PGPException */ public void decrypt(InputStream input, OutputStream output) throws IOException, PGPException { PGPObjectFactory in = new PGPObjectFactory(new ArmoredInputStream(input)); Object object = in.nextObject(); if (object instanceof PGPEncryptedDataList) { PGPEncryptedDataList pgpstream = (PGPEncryptedDataList) object; Iterator<?> it = pgpstream.getEncryptedDataObjects(); /* iterate over content until a message has been found */ while (it.hasNext()) { Object o = it.next(); if (o instanceof PGPPublicKeyEncryptedData) { PGPPublicKeyEncryptedData pgp = (PGPPublicKeyEncryptedData) o; InputStream decrypted = pgp.getDataStream(privatekey, new BouncyCastleProvider()); /* the stream is still zipped, so we have to unzip it... */ PGPObjectFactory unzip_object = new PGPObjectFactory(decrypted); PGPCompressedData unzipped = (PGPCompressedData) unzip_object.nextObject(); /* and literal ... */ PGPObjectFactory literal_object = new PGPObjectFactory(unzipped.getDataStream()); PGPLiteralData literal = (PGPLiteralData) literal_object.nextObject(); IOUtils.copy(literal.getDataStream(), output); break; } } } else { throw new PGPException( "Stream is not a PGPEncryptedDataList stream :" + object.getClass().getSimpleName()); } }
From source file:de.loercher.geomodule.commons.SecurityHelper.java
License:Apache License
public SecurityHelper() { Security.addProvider(new BouncyCastleProvider()); }
From source file:de.mendelson.util.security.BCCryptoHelper.java
public void initialize() { Security.addProvider(new BouncyCastleProvider()); MailcapCommandMap mc = (MailcapCommandMap) CommandMap.getDefaultCommandMap(); mc.addMailcap(// ww w . j av a 2 s. c o m "application/pkcs7-signature;; x-java-content-handler=org.bouncycastle.mail.smime.handlers.pkcs7_signature"); mc.addMailcap( "application/pkcs7-mime;; x-java-content-handler=org.bouncycastle.mail.smime.handlers.pkcs7_mime"); mc.addMailcap( "application/x-pkcs7-signature;; x-java-content-handler=org.bouncycastle.mail.smime.handlers.x_pkcs7_signature"); mc.addMailcap( "application/x-pkcs7-mime;; x-java-content-handler=org.bouncycastle.mail.smime.handlers.x_pkcs7_mime"); mc.addMailcap( "multipart/signed;; x-java-content-handler=org.bouncycastle.mail.smime.handlers.multipart_signed"); CommandMap.setDefaultCommandMap(mc); //As of JavaMail 1.4.1 and later caching was introduced for Multipart objects, //this can cause some issues for signature verification as occasionally the cache does not produce exactly //the same message as was read in. System.setProperty("mail.mime.cachemultipart", "false"); }
From source file:de.mendelson.util.security.cert.gui.JDialogCertificates.java
/** * Imports a certificate into the keystore *///from w w w . j a va 2s . co m private void importCertificate() { if (!this.isOperationAllowed()) { return; } JFrame parent = (JFrame) SwingUtilities.getAncestorOfClass(JFrame.class, this); MecFileChooser chooser = new MecFileChooser(parent, this.rb.getResourceString("filechooser.certificate.import")); String importFilename = chooser.browseFilename(); if (importFilename == null) { return; } JDialogInfoOnExternalCertificate infoDialog = new JDialogInfoOnExternalCertificate(parent, new File(importFilename)); infoDialog.setVisible(true); if (!infoDialog.importPressed()) { return; } int selectedCertificateIndex = infoDialog.getCertificateIndex(); FileInputStream inStream = null; try { KeyStoreUtil util = new KeyStoreUtil(); Provider provBC = new BouncyCastleProvider(); inStream = new FileInputStream(importFilename); List<X509Certificate> certList = util.readCertificates(inStream, provBC); X509Certificate importCertificate = certList.get(selectedCertificateIndex); String proposedAlias = util.getProposalCertificateAliasForImport(importCertificate); String alias = JOptionPane.showInputDialog(this, this.rb.getResourceString("certificate.import.alias"), proposedAlias); if (alias == null || alias.trim().length() == 0) { return; } util.importX509Certificate(this.manager.getKeystore(), importFilename, alias, provBC); this.manager.saveKeystore(); this.manager.rereadKeystoreCertificates(); this.panelCertificates.refreshData(); this.panelCertificates.certificateAdded(alias); KeystoreCertificate keystoreCertificate = this.manager.getKeystoreCertificate(alias); String messageKey = "certificate.import.success.message"; if (keystoreCertificate.isRootCertificate()) { messageKey = "certificate.root.import.success.message"; } JOptionPane.showMessageDialog(this, this.rb.getResourceString(messageKey, alias), this.rb.getResourceString("certificate.import.success.title"), JOptionPane.INFORMATION_MESSAGE); //multiple certificates: show the import dialog again if (certList.size() > 1) { infoDialog.setVisible(true); } } catch (Throwable e) { e.printStackTrace(); JOptionPane.showMessageDialog(this, this.rb.getResourceString("certificate.import.error.message", e.getMessage()), this.rb.getResourceString("certificate.import.error.title"), JOptionPane.ERROR_MESSAGE); } finally { if (inStream != null) { try { inStream.close(); } catch (Exception e) { //nop } } } }
From source file:de.mendelson.util.security.cert.gui.JDialogInfoOnExternalCertificate.java
private List<String> getInfo(File certFile) { List<String> infoList = null; FileInputStream inStream = null; try {/* w w w .j av a 2s .c o m*/ Provider provBC = new BouncyCastleProvider(); inStream = new FileInputStream(certFile); KeyStoreUtil util = new KeyStoreUtil(); List<X509Certificate> certList = util.readCertificates(inStream, provBC); infoList = this.getInfo(certList); //add file info to info text StringBuilder fileInfoText = new StringBuilder(); fileInfoText.append(this.rb.getResourceString("certinfo.certfile", certFile.getAbsolutePath())); fileInfoText.append("\n---\n"); for (int i = 0; i < infoList.size(); i++) { infoList.set(i, fileInfoText.toString() + infoList.get(i)); } } catch (Exception e) { this.certificateIsOk = false; infoList.clear(); infoList.add(e.getMessage()); } finally { try { if (inStream != null) { inStream.close(); } } catch (Exception e) { //nop } } return (infoList); }
From source file:de.mendelson.util.security.PEMKeys2Keystore.java
/** * Creates a new instance of PEMUtil//from w w w . j av a 2s . co m * * @param logger Logger to log the information to */ public PEMKeys2Keystore(Logger logger, String targetKeystoreType) { this.logger = logger; this.targetKeystoreType = targetKeystoreType; //forget it to work without BC at this point, the SUN JCE provider //could not handle pcks12 Security.addProvider(new BouncyCastleProvider()); }
From source file:de.mendelson.util.security.PEMKeys2PKCS12.java
/** * Creates a new instance of PEMUtil/* www .j a va 2 s.c o m*/ * * @param logger Logger to log the information to */ public PEMKeys2PKCS12(Logger logger) { this.logger = logger; //forget it to work without BC at this point, the SUN JCE provider //could not handle pcks12 Security.addProvider(new BouncyCastleProvider()); }