* {@inheritDoc}
*/
public void initialize(OutputStream out) throws Exception
{
InputStream decodedInputStream = PGPUtil.getDecoderStream(this.toBeDecrypted);
PGPObjectFactory pgpF = new PGPObjectFactory(decodedInputStream);
Object o = pgpF.nextObject();
if (o == null)
{
throw new IllegalArgumentException("Invalid PGP message");
}
// the first object might be a PGP marker packet.
PGPEncryptedDataList enc;
if (o instanceof PGPEncryptedDataList)
{
enc = (PGPEncryptedDataList) o;
}
else
{
enc = (PGPEncryptedDataList) pgpF.nextObject();
}
// This loop looks like it is ready for multiple encrypted
// objects, but really only one is expected.
Iterator it = enc.getEncryptedDataObjects();
PGPPublicKeyEncryptedData pbe = null;
PGPPrivateKey privateKey = null;
while (privateKey == null && it.hasNext())
{
pbe = (PGPPublicKeyEncryptedData) it.next();
privateKey = getPrivateKey(pbe.getKeyID(), this.password);
if (privateKey == null)
{
throw new IllegalArgumentException("Failed to find private key with ID " + pbe.getKeyID());
}
}
clearStream = pbe.getDataStream(privateKey, "BC");
PGPObjectFactory plainFact = new PGPObjectFactory(clearStream);
o = plainFact.nextObject();
PGPOnePassSignature signature = null;
if (o instanceof PGPOnePassSignatureList)
{
PGPOnePassSignatureList list = (PGPOnePassSignatureList) o;
signature = list.get(0);
signature.initVerify(this.publicKey, "BC");
// TODO verify signature
// signature.verify(null);
o = plainFact.nextObject();
}
compressedStream = null;
if (o instanceof PGPCompressedData)
{
PGPCompressedData cData = (PGPCompressedData) o;
compressedStream = new BufferedInputStream(cData.getDataStream());
PGPObjectFactory pgpFact = new PGPObjectFactory(compressedStream);
Object streamData = pgpFact.nextObject();
o = streamData;
}
if (o instanceof PGPLiteralData)
{