当前位置: 首页>>代码示例>>Java>>正文


Java PGPCompressedData.getDataStream方法代码示例

本文整理汇总了Java中org.bouncycastle.openpgp.PGPCompressedData.getDataStream方法的典型用法代码示例。如果您正苦于以下问题:Java PGPCompressedData.getDataStream方法的具体用法?Java PGPCompressedData.getDataStream怎么用?Java PGPCompressedData.getDataStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bouncycastle.openpgp.PGPCompressedData的用法示例。


在下文中一共展示了PGPCompressedData.getDataStream方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testCompressDecompress

import org.bouncycastle.openpgp.PGPCompressedData; //导入方法依赖的package包/类
@Test
public void testCompressDecompress() throws Exception {
  // Compress the data and write out a compressed data OpenPGP message.
  byte[] data;
  try (ByteArrayOutputStream output = new ByteArrayOutputStream()) {
    PGPCompressedDataGenerator kompressor = new PGPCompressedDataGenerator(ZIP);
    try (OutputStream output2 = kompressor.open(output)) {
      output2.write(FALL_OF_HYPERION_A_DREAM.getBytes(UTF_8));
    }
    data = output.toByteArray();
  }
  logger.info("Compressed data: " + dumpHex(data));

  // Decompress the data.
  try (ByteArrayInputStream input = new ByteArrayInputStream(data)) {
    PGPObjectFactory pgpFact = new BcPGPObjectFactory(input);
    PGPCompressedData object = (PGPCompressedData) pgpFact.nextObject();
    InputStream original = object.getDataStream();  // Closing this would close input.
    assertThat(CharStreams.toString(new InputStreamReader(original, UTF_8)))
        .isEqualTo(FALL_OF_HYPERION_A_DREAM);
    assertThat(pgpFact.nextObject()).isNull();
  }
}
 
开发者ID:google,项目名称:nomulus,代码行数:24,代码来源:BouncyCastleTest.java

示例2: validateData

import org.bouncycastle.openpgp.PGPCompressedData; //导入方法依赖的package包/类
private void validateData(byte[] data)
    throws IOException, PGPException
{
    PGPObjectFactory pgpFact = new PGPObjectFactory(data);
    PGPCompressedData c1 = (PGPCompressedData)pgpFact.nextObject();
    InputStream pIn = c1.getDataStream();

    ByteArrayOutputStream bOut = new ByteArrayOutputStream();

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

    if (!areEqual(bOut.toByteArray(), "hello world! !dlrow olleh".getBytes()))
    {
        fail("compression test failed");
    }
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:21,代码来源:PGPCompressionTest.java

示例3: asLiteral

import org.bouncycastle.openpgp.PGPCompressedData; //导入方法依赖的package包/类
/**
 * ***********************************************
 */
private static PGPLiteralData asLiteral( final InputStream clear ) throws IOException, PGPException
{
    final PGPObjectFactory plainFact = new PGPObjectFactory( clear, new JcaKeyFingerprintCalculator() );
    final Object message = plainFact.nextObject();
    if ( message instanceof PGPCompressedData )
    {
        final PGPCompressedData cData = ( PGPCompressedData ) message;
        final PGPObjectFactory pgpFact =
                new PGPObjectFactory( cData.getDataStream(), new JcaKeyFingerprintCalculator() );
        // Find the first PGPLiteralData object
        Object object = null;
        for ( int safety = 0; ( safety++ < 1000 ) && !( object instanceof PGPLiteralData );
              object = pgpFact.nextObject() )
        {
            //ignore
        }
        return ( PGPLiteralData ) object;
    }
    else if ( message instanceof PGPLiteralData )
    {
        return ( PGPLiteralData ) message;
    }
    else if ( message instanceof PGPOnePassSignatureList )
    {
        throw new PGPException( "encrypted message contains a signed message - not literal data." );
    }
    else
    {
        throw new PGPException(
                "message is not a simple encrypted file - type unknown: " + message.getClass().getName() );
    }
}
 
开发者ID:subutai-io,项目名称:base,代码行数:36,代码来源:PGPEncryptionUtil.java

示例4: testCompression

import org.bouncycastle.openpgp.PGPCompressedData; //导入方法依赖的package包/类
private void testCompression(
    int type)
    throws IOException, PGPException
{
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    PGPCompressedDataGenerator cPacket = new PGPCompressedDataGenerator(type);

    OutputStream out = cPacket.open(new UncloseableOutputStream(bOut));

    out.write("hello world!".getBytes());

    out.close();

    PGPObjectFactory pgpFact = new PGPObjectFactory(bOut.toByteArray());
    PGPCompressedData c1 = (PGPCompressedData)pgpFact.nextObject();
    InputStream pIn = c1.getDataStream();

    bOut.reset();

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

    if (!areEqual(bOut.toByteArray(), "hello world!".getBytes()))
    {
        fail("compression test failed");
    }
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:31,代码来源:PGPCompressionTest.java

示例5: getInputStream

import org.bouncycastle.openpgp.PGPCompressedData; //导入方法依赖的package包/类
private static InputStream getInputStream( PGPPrivateKey privateKey, PGPPublicKeyEncryptedData pgpEncData )
        throws PGPException, IOException
{
    InputStream is = pgpEncData
            .getDataStream( new JcePublicKeyDataDecryptorFactoryBuilder().setProvider( "BC" ).build( privateKey ) );

    JcaPGPObjectFactory objectFactory = new JcaPGPObjectFactory( is );

    Object message = objectFactory.nextObject();

    PGPCompressedData compressedData = ( PGPCompressedData ) message;

    JcaPGPObjectFactory pgpObjectFactory = new JcaPGPObjectFactory( compressedData.getDataStream() );

    PGPLiteralData literalData = ( PGPLiteralData ) pgpObjectFactory.nextObject();

    return literalData.getInputStream();
}
 
开发者ID:subutai-io,项目名称:base,代码行数:19,代码来源:PGPDecrypt.java

示例6: getObjectFactory

import org.bouncycastle.openpgp.PGPCompressedData; //导入方法依赖的package包/类
private static JcaPGPObjectFactory getObjectFactory( byte signedData[] ) throws IOException, PGPException
{
    InputStream in = PGPUtil.getDecoderStream( new ByteArrayInputStream( signedData ) );

    JcaPGPObjectFactory pgpFact = new JcaPGPObjectFactory( in );

    PGPCompressedData compressedData = ( PGPCompressedData ) pgpFact.nextObject();

    return new JcaPGPObjectFactory( compressedData.getDataStream() );
}
 
开发者ID:subutai-io,项目名称:base,代码行数:11,代码来源:PGPVerify.java

示例7: openDecompressor

import org.bouncycastle.openpgp.PGPCompressedData; //导入方法依赖的package包/类
/**
 * Opens a new {@link Decompressor} (Reading Step 2/3)
 *
 * <p>This is the second step in reading a ghostryde file. After this method, you'll want to
 * call {@link #openInput(Decompressor)}.
 *
 * @param input is the value returned by {@link #openDecryptor}.
 * @throws IOException
 * @throws PGPException
 */
@CheckReturnValue
public Decompressor openDecompressor(@WillNotClose Decryptor input)
    throws IOException, PGPException {
  PGPObjectFactory fact = new BcPGPObjectFactory(checkNotNull(input, "input"));
  PGPCompressedData compressed = pgpCast(fact.nextObject(), PGPCompressedData.class);
  return new Decompressor(compressed.getDataStream());
}
 
开发者ID:google,项目名称:nomulus,代码行数:18,代码来源:Ghostryde.java


注:本文中的org.bouncycastle.openpgp.PGPCompressedData.getDataStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。