*/
@Override
public void initialize(OutputStream out) throws Exception
{
InputStream decodedInputStream = PGPUtil.getDecoderStream(this.toBeDecrypted);
PGPObjectFactory pgpF = new PGPObjectFactory(decodedInputStream);
Object pgpObject = pgpF.nextObject();
if (pgpObject == null)
{
throw new IllegalArgumentException("Invalid PGP message");
}
// the first object might be a PGP marker packet.
PGPEncryptedDataList enc;
if (pgpObject instanceof PGPEncryptedDataList)
{
enc = (PGPEncryptedDataList) pgpObject;
}
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, provider);
PGPObjectFactory pgpObjectFactory = new PGPObjectFactory(clearStream);
pgpObject = pgpObjectFactory.nextObject();
while (!(pgpObject instanceof PGPLiteralData))
{
if (pgpObject instanceof PGPOnePassSignatureList)
{
PGPOnePassSignature signature = null;
PGPOnePassSignatureList list = (PGPOnePassSignatureList) pgpObject;
signature = list.get(0);
signature.initVerify(this.publicKey, provider);
// TODO verify signature
// signature.verify(null);
pgpObject = pgpObjectFactory.nextObject();
}
else if (pgpObject instanceof PGPCompressedData)
{
PGPCompressedData cData = (PGPCompressedData) pgpObject;
compressedStream = new BufferedInputStream(cData.getDataStream());
pgpObjectFactory = new PGPObjectFactory(compressedStream);
pgpObject = pgpObjectFactory.nextObject();
}
else
{
throw new PGPException("input is not PGPLiteralData - type unknown.");
}