Date date)
throws Exception
{
PGPObjectFactory pgpF = new PGPObjectFactory(message);
PGPEncryptedDataList enc = (PGPEncryptedDataList)pgpF.nextObject();
PGPPBEEncryptedData pbe = (PGPPBEEncryptedData)enc.get(0);
InputStream clear = pbe.getDataStream(new BcPBEDataDecryptorFactory(pass, new BcPGPDigestCalculatorProvider()));
PGPObjectFactory pgpFact = new PGPObjectFactory(clear);
PGPCompressedData cData = (PGPCompressedData)pgpFact.nextObject();
pgpFact = new PGPObjectFactory(cData.getDataStream());
PGPLiteralData ld = (PGPLiteralData)pgpFact.nextObject();
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
if (!ld.getFileName().equals("test.txt")
&& !ld.getFileName().equals("_CONSOLE"))
{
fail("wrong filename in packet");
}
if (!ld.getModificationTime().equals(date))
{
fail("wrong modification time in packet: " + ld.getModificationTime().getTime() + " " + date.getTime());
}
InputStream unc = ld.getInputStream();
byte[] buf = new byte[1024];
int len;
while ((len = unc.read(buf)) >= 0)
{
bOut.write(buf, 0, len);
}
if (pbe.isIntegrityProtected() && !pbe.verify())
{
fail("integrity check failed");
}
return bOut.toByteArray();