List of usage examples for org.bouncycastle.bcpg BCPGOutputStream writePacket
public void writePacket(ContainedPacket p) throws IOException
From source file:genkeys.java
License:Open Source License
private static void exportSecretKey(OutputStream out, KeyPair key, int cipher, int s2kmode, int hashAlgorithm, boolean useSHA1, String pass, boolean armor) throws IOException, NoSuchProviderException, PGPException { if (armor) {/*from ww w . j a v a 2s. c o m*/ out = new ArmoredOutputStream(out); } SecureRandom rand = new SecureRandom(); byte[] iv = new byte[8]; rand.nextBytes(iv); S2K s2k = new S2K(hashAlgorithm, iv, 0x60); SecretKeyPacket packet = secretKeyPacket(key, cipher, useSHA1, s2k, pass); BCPGOutputStream bcOut; if (out instanceof BCPGOutputStream) { bcOut = (BCPGOutputStream) out; } else { bcOut = new BCPGOutputStream(out); } bcOut.writePacket(packet); if (armor) { out.close(); } }
From source file:org.sufficientlysecure.keychain.pgp.WrappedUserAttribute.java
License:Open Source License
/** Writes this object to an ObjectOutputStream. */ private void writeObject(java.io.ObjectOutputStream out) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); BCPGOutputStream bcpg = new BCPGOutputStream(baos); bcpg.writePacket(new UserAttributePacket(mVector.toSubpacketArray())); out.writeObject(baos.toByteArray()); }