Java 类org.bouncycastle.openpgp.PGPPBEEncryptedData 实例源码

项目:jpgpj    文件:Decryptor.java   
/**
 * Decrypts the encrypted data as the returned input stream.
 */
protected InputStream decrypt(PGPPBEEncryptedData data)
throws IOException, PGPException {
    if (data == null || Util.isEmpty(symmetricPassphrase))
        throw new DecryptionException("no suitable decryption key found");

    try {
        return data.getDataStream(buildSymmetricKeyDecryptor(
            symmetricPassphrase));
    } catch (PGPDataValidationException e) {
        throw new PassphraseException(
            "incorrect passphrase for symmetric key", e);
    }
}
项目:gwt-crypto    文件:BcPGPPBETest.java   
/**
 * decrypt the passed in message stream
 */
private byte[] decryptMessage(
    byte[]    message,
    Date      date)
    throws Exception
{
    PGPObjectFactory         pgpF = new BcPGPObjectFactory(message);
    PGPEncryptedDataList     enc = (PGPEncryptedDataList)pgpF.nextObject();
    PGPPBEEncryptedData      pbe = (PGPPBEEncryptedData)enc.get(0);

    InputStream clear = pbe.getDataStream(new BcPBEDataDecryptorFactory(pass, new BcPGPDigestCalculatorProvider()));

    PGPObjectFactory         pgpFact = new BcPGPObjectFactory(clear);

    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();
    int                      ch;

    while ((ch = unc.read()) >= 0)
    {
        bOut.write(ch);
    }

    if (pbe.isIntegrityProtected() && !pbe.verify())
    {
        fail("integrity check failed");
    }

    return bOut.toByteArray();
}
项目:gwt-crypto    文件:BcPGPPBETest.java   
private byte[] decryptMessageBuffered(
    byte[]    message,
    Date      date)
    throws Exception
{
    PGPObjectFactory         pgpF = new PGPObjectFactory(message, new BcKeyFingerprintCalculator());
    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, new BcKeyFingerprintCalculator());

    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();
}
项目:irma_future_id    文件:BcPGPPBETest.java   
/**
 * decrypt the passed in message stream
 */
private byte[] decryptMessage(
    byte[]    message,
    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);

    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();
    int                      ch;

    while ((ch = unc.read()) >= 0)
    {
        bOut.write(ch);
    }

    if (pbe.isIntegrityProtected() && !pbe.verify())
    {
        fail("integrity check failed");
    }

    return bOut.toByteArray();
}
项目:irma_future_id    文件:BcPGPPBETest.java   
private byte[] decryptMessageBuffered(
    byte[]    message,
    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);;

    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();
}
项目:bc-java    文件:BcPGPPBETest.java   
/**
 * decrypt the passed in message stream
 */
private byte[] decryptMessage(
    byte[]    message,
    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);

    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();
    int                      ch;

    while ((ch = unc.read()) >= 0)
    {
        bOut.write(ch);
    }

    if (pbe.isIntegrityProtected() && !pbe.verify())
    {
        fail("integrity check failed");
    }

    return bOut.toByteArray();
}
项目:bc-java    文件:BcPGPPBETest.java   
private byte[] decryptMessageBuffered(
    byte[]    message,
    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);;

    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();
}