List of usage examples for org.bouncycastle.openpgp PGPSecretKeyRing PGPSecretKeyRing
public PGPSecretKeyRing(List secKeys)
From source file:com.geekcommune.identity.EncryptionUtil.java
License:Open Source License
/** * Get the keyring pointed to by the public & secret files. Creates the files * with a single key if they don't already exist; interrogates keyDataSource for the * info to create the key (typically it should pop up a gui). * // w w w.java 2s. c o m * TODO bobby: doesn't create usable keyrings yet, and doesn't save what it does create :-( * @param publicKeyRingFile * @param secretKeyRingFile * @param keyDataSource * @return * @throws PGPException * @throws FileNotFoundException * @throws IOException * @throws NoSuchAlgorithmException * @throws NoSuchProviderException * @throws InvalidAlgorithmParameterException */ public Pair<PGPPublicKeyRingCollection, PGPSecretKeyRingCollection> getOrCreateKeyring(File publicKeyRingFile, File secretKeyRingFile, KeyDataSource keyDataSource) throws PGPException, FileNotFoundException, IOException, NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException { boolean pubRingFound = publicKeyRingFile.isFile(); boolean secRingFound = secretKeyRingFile.isFile(); if (pubRingFound != secRingFound) { throw new PGPException("Expect both public & secret keyring, or neither: " + publicKeyRingFile + ", " + secretKeyRingFile); } Pair<PGPPublicKeyRingCollection, PGPSecretKeyRingCollection> retval = new Pair<PGPPublicKeyRingCollection, PGPSecretKeyRingCollection>(); if (pubRingFound) { retval.setFirst(EncryptionUtil.instance().readPublicKeyRingCollection(publicKeyRingFile)); retval.setSecond(EncryptionUtil.instance().readSecretKeyRingCollection(secretKeyRingFile)); } else { if (publicKeyRingFile.exists() || secretKeyRingFile.exists()) { throw new PGPException("Either public or secret keyring not a normal file: " + publicKeyRingFile + ", " + secretKeyRingFile); } PGPSecretKey key = generateKey(keyDataSource.getIdentity(), keyDataSource.getPassphrase()); PGPPublicKeyRing publicKeyRing = new PGPPublicKeyRing(key.getPublicKey().getEncoded()); Collection<PGPPublicKeyRing> collection = Collections.singletonList(publicKeyRing); retval.setFirst(new PGPPublicKeyRingCollection(collection)); PGPSecretKeyRing secretKeyRing = new PGPSecretKeyRing(key.getEncoded()); Collection<PGPSecretKeyRing> secretKeyRings = Collections.singletonList(secretKeyRing); retval.setSecond(new PGPSecretKeyRingCollection(secretKeyRings)); //TODO bobby save keyrings to the files } return retval; }
From source file:de.jtheuer.diki.lib.pgp.PGPHandler.java
License:Open Source License
/** * Creates a new {@link PGPHandler} from already existing PGP keys which are normally loaded from the * file-system using a {@link FileInputStream}. * @param privatekeystream/*from w w w .java 2 s. c o m*/ * @param passphrase * @param identity * @param publickeyring * @throws IOException * @throws PGPException * @throws NoSuchProviderException */ public PGPHandler(InputStream privatekeystream, char[] passphrase, String identity, InputStream publickeyring) throws IOException, PGPException, NoSuchProviderException { this(); PGPSecretKeyRing secretKeyring = new PGPSecretKeyRing(privatekeystream); init(secretKeyring.getSecretKey(), passphrase, identity); if (publickeyring != null) { keyring = new PGPPublicKeyRingCollection(publickeyring); } else { keyring = new PGPPublicKeyRingCollection(new LinkedList<PGPPublicKey>()); } }
From source file:net.pgp2p.cryptoservice.PGPManager.java
License:Open Source License
/** * Instanciates the PGPManager informing the directory in which the * pubring and secring will be stored./* w ww . j ava 2s . c o m*/ * * @param path * @throws FileNotFoundException * @throws IOException * @throws PGPException */ public PGPManager(String path) throws FileNotFoundException, IOException, PGPException { setKeyRingPath(path); this.pubringFilePath = path + System.getProperty("file.separator") + PUBRING_FILE; publicKeyRing = new PGPPublicKeyRingCollection(new FileInputStream(this.pubringFilePath)); this.secringFilePath = path + System.getProperty("file.separator") + SECRING_FILE; secretKeyRing = new PGPSecretKeyRing(new FileInputStream(this.secringFilePath)); prepareKeyRing(); }
From source file:org.brownsocks.payments.gateways.enets.pgp.BCPGPProvider.java
@Override public void initialize(String privateKey, String privateKeyPass, String publicKey) throws IOException, PGPException, NoSuchProviderException { _provider = new BouncyCastleProvider(); _passphrase = privateKeyPass;//w w w .j a va2s . c o m _secretKeyRing = new PGPSecretKeyRing( PGPUtil.getDecoderStream(new ByteArrayInputStream(privateKey.getBytes()))); _remotePublicKeyRing = new PGPPublicKeyRingCollection( PGPUtil.getDecoderStream(new ByteArrayInputStream(publicKey.getBytes()))); }