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


Java PGPLiteralDataGenerator类代码示例

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


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

示例1: encrypt

import org.bouncycastle.openpgp.PGPLiteralDataGenerator; //导入依赖的package包/类
public static byte[] encrypt( final byte[] message, final PGPPublicKey publicKey, boolean armored )
        throws PGPException
{
    try
    {
        final ByteArrayInputStream in = new ByteArrayInputStream( message );
        final ByteArrayOutputStream bOut = new ByteArrayOutputStream();
        final PGPLiteralDataGenerator literal = new PGPLiteralDataGenerator();
        final PGPCompressedDataGenerator comData = new PGPCompressedDataGenerator( CompressionAlgorithmTags.ZIP );
        final OutputStream pOut =
                literal.open( comData.open( bOut ), PGPLiteralData.BINARY, "filename", in.available(), new Date() );
        Streams.pipeAll( in, pOut );
        comData.close();
        final byte[] bytes = bOut.toByteArray();
        final PGPEncryptedDataGenerator generator = new PGPEncryptedDataGenerator(
                new JcePGPDataEncryptorBuilder( SymmetricKeyAlgorithmTags.AES_256 ).setWithIntegrityPacket( true )
                                                                                   .setSecureRandom(
                                                                                           new SecureRandom() )

                                                                                   .setProvider( provider ) );
        generator.addMethod( new JcePublicKeyKeyEncryptionMethodGenerator( publicKey ).setProvider( provider ) );
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        OutputStream theOut = armored ? new ArmoredOutputStream( out ) : out;
        OutputStream cOut = generator.open( theOut, bytes.length );
        cOut.write( bytes );
        cOut.close();
        theOut.close();
        return out.toByteArray();
    }
    catch ( Exception e )
    {
        throw new PGPException( "Error in encrypt", e );
    }
}
 
开发者ID:subutai-io,项目名称:base,代码行数:35,代码来源:PGPEncryptionUtil.java

示例2: produceSign

import org.bouncycastle.openpgp.PGPLiteralDataGenerator; //导入依赖的package包/类
private static void produceSign( byte[] data, BCPGOutputStream bcOut, PGPSignatureGenerator signGen )
        throws IOException, PGPException
{
    PGPLiteralDataGenerator literalGen = new PGPLiteralDataGenerator();

    OutputStream os = literalGen.open( bcOut, PGPLiteralData.BINARY, "", data.length, new Date() );

    InputStream is = new ByteArrayInputStream( data );

    int ch;

    while ( ( ch = is.read() ) >= 0 )
    {
        signGen.update( ( byte ) ch );
        os.write( ch );
    }

    literalGen.close();

    signGen.generate().encode( bcOut );
}
 
开发者ID:subutai-io,项目名称:base,代码行数:22,代码来源:PGPSign.java

示例3: createEncryptedNonCompressedData

import org.bouncycastle.openpgp.PGPLiteralDataGenerator; //导入依赖的package包/类
void createEncryptedNonCompressedData(ByteArrayOutputStream bos, String keyringPath) throws Exception, IOException, PGPException,
        UnsupportedEncodingException {
    PGPEncryptedDataGenerator encGen = new PGPEncryptedDataGenerator(new JcePGPDataEncryptorBuilder(SymmetricKeyAlgorithmTags.CAST5)
            .setSecureRandom(new SecureRandom()).setProvider(getProvider()));
    encGen.addMethod(new JcePublicKeyKeyEncryptionMethodGenerator(readPublicKey(keyringPath)));
    OutputStream encOut = encGen.open(bos, new byte[512]);
    PGPLiteralDataGenerator litData = new PGPLiteralDataGenerator();
    OutputStream litOut = litData.open(encOut, PGPLiteralData.BINARY, PGPLiteralData.CONSOLE, new Date(), new byte[512]);

    try {
        litOut.write("Test Message Without Compression".getBytes("UTF-8"));
        litOut.flush();
    } finally {
        IOHelper.close(litOut);
        IOHelper.close(encOut, bos);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:PGPDataFormatTest.java

示例4: compress

import org.bouncycastle.openpgp.PGPLiteralDataGenerator; //导入依赖的package包/类
private static byte[] compress(byte[] clearData, String fileName, int algorithm) throws IOException
{
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    PGPCompressedDataGenerator comData = new PGPCompressedDataGenerator(algorithm);
    OutputStream cos = comData.open(bOut); // open it with the final destination

    PGPLiteralDataGenerator lData = new PGPLiteralDataGenerator();

    // we want to generate compressed data. This might be a user option later,
    // in which case we would pass in bOut.
    OutputStream  pOut = lData.open(cos, // the compressed output stream
                                    PGPLiteralData.BINARY,
                                    fileName,  // "filename" to store
                                    clearData.length, // length of clear data
                                    new Date()  // current time
                                  );

    pOut.write(clearData);
    pOut.close();

    comData.close();

    return bOut.toByteArray();
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:25,代码来源:ByteArrayHandler.java

示例5: readBackTest

import org.bouncycastle.openpgp.PGPLiteralDataGenerator; //导入依赖的package包/类
private void readBackTest(
    PGPLiteralDataGenerator generator)
    throws IOException
{
    Random                  rand = new Random();
    byte[]                  buf = new byte[MAX];
    
    rand.nextBytes(buf);
    
    for (int i = 1; i <= 200; i++)
    {
        bufferTest(generator, buf, i);
    }
    
    bufferTest(generator, buf, 8382);
    bufferTest(generator, buf, 8383);
    bufferTest(generator, buf, 8384);
    bufferTest(generator, buf, 8385);
    
    for (int i = 200; i < MAX; i += 100)
    {
        bufferTest(generator, buf, i);
    }
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:25,代码来源:PGPPacketTest.java

示例6: writeBytesToLiteralData

import org.bouncycastle.openpgp.PGPLiteralDataGenerator; //导入依赖的package包/类
private static void writeBytesToLiteralData(OutputStream out, char fileType, String name, byte[] bytes)
		throws IOException
{
	PGPLiteralDataGenerator lData = new PGPLiteralDataGenerator();
	OutputStream pOut = lData.open(out, fileType, name, bytes.length, new Date());
	pOut.write(bytes);
}
 
开发者ID:AnonymOnline,项目名称:saveOrganizer,代码行数:8,代码来源:Encryption.java

示例7: packet

import org.bouncycastle.openpgp.PGPLiteralDataGenerator; //导入依赖的package包/类
/**
 * Wraps with stream that ouputs literal data packet.
 */
protected OutputStream packet(OutputStream out, FileMetadata meta)
throws IOException, PGPException {
    char format = meta.getFormat().getCode();
    String name = meta.getName();
    Date date = meta.getLastModifiedDate();
    byte[] buf = getLiteralBuffer(meta);
    return new PGPLiteralDataGenerator().open(out, format, name, date, buf);
}
 
开发者ID:justinludwig,项目名称:jpgpj,代码行数:12,代码来源:Encryptor.java

示例8: createDelegate

import org.bouncycastle.openpgp.PGPLiteralDataGenerator; //导入依赖的package包/类
private static OutputStream
    createDelegate(int bufferSize, OutputStream os, DateTime modified, String filename) {
  try {
    checkArgument(filename.endsWith(".tar"),
        "Ryde PGP message should contain a tar file.");
    return new PGPLiteralDataGenerator().open(
        os, BINARY, filename, modified.toDate(), new byte[bufferSize]);
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:google,项目名称:nomulus,代码行数:12,代码来源:RydePgpFileOutputStream.java

示例9: testExceptionDecryptorIncorrectInputFormatSymmetricEncryptedData

import org.bouncycastle.openpgp.PGPLiteralDataGenerator; //导入依赖的package包/类
@Test
public void testExceptionDecryptorIncorrectInputFormatSymmetricEncryptedData() throws Exception {

    byte[] payload = "Not Correct Format".getBytes("UTF-8");
    ByteArrayOutputStream bos = new ByteArrayOutputStream();

    PGPEncryptedDataGenerator encGen = new PGPEncryptedDataGenerator(new JcePGPDataEncryptorBuilder(SymmetricKeyAlgorithmTags.CAST5)
            .setSecureRandom(new SecureRandom()).setProvider(getProvider()));

    encGen.addMethod(new JcePBEKeyEncryptionMethodGenerator("pw".toCharArray()));

    OutputStream encOut = encGen.open(bos, new byte[1024]);
    PGPCompressedDataGenerator comData = new PGPCompressedDataGenerator(CompressionAlgorithmTags.ZIP);
    OutputStream comOut = new BufferedOutputStream(comData.open(encOut));
    PGPLiteralDataGenerator litData = new PGPLiteralDataGenerator();
    OutputStream litOut = litData.open(comOut, PGPLiteralData.BINARY, PGPLiteralData.CONSOLE, new Date(), new byte[1024]);
    litOut.write(payload);
    litOut.flush();
    litOut.close();
    comOut.close();
    encOut.close();
    MockEndpoint mock = getMockEndpoint("mock:exception");
    mock.expectedMessageCount(1);
    template.sendBody("direct:subkeyUnmarshal", bos.toByteArray());
    assertMockEndpointsSatisfied();

    checkThrownException(mock, IllegalArgumentException.class, null, "The input message body has an invalid format.");
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:29,代码来源:PGPDataFormatTest.java

示例10: encryptString

import org.bouncycastle.openpgp.PGPLiteralDataGenerator; //导入依赖的package包/类
public String encryptString(PGPPublicKey key, String clearText)
		throws IOException, PGPException {

	byte[] clearData = clearText.getBytes(StandardCharsets.UTF_8);

	ByteArrayOutputStream encOut = new ByteArrayOutputStream();
	OutputStream out = new ArmoredOutputStream(encOut);
	ByteArrayOutputStream bOut = new ByteArrayOutputStream();

	PGPCompressedDataGenerator comData = new PGPCompressedDataGenerator(
			PGPCompressedDataGenerator.ZIP);
	OutputStream cos = comData.open(bOut);
	PGPLiteralDataGenerator lData = new PGPLiteralDataGenerator();

	OutputStream pOut = lData.open(cos, PGPLiteralData.BINARY,
			PGPLiteralData.CONSOLE, clearData.length, new Date());
	pOut.write(clearData);

	lData.close();
	comData.close();

	PGPEncryptedDataGenerator encGen = new PGPEncryptedDataGenerator(
			new JcePGPDataEncryptorBuilder(PGPEncryptedData.CAST5)
					.setWithIntegrityPacket(true)
					.setSecureRandom(new SecureRandom()).setProvider(BouncyCastleProvider.PROVIDER_NAME));

	encGen.addMethod(new JcePublicKeyKeyEncryptionMethodGenerator(key)
			.setProvider(BouncyCastleProvider.PROVIDER_NAME));

	byte[] bytes = bOut.toByteArray();
	OutputStream cOut = encGen.open(out, bytes.length);
	cOut.write(bytes);
	cOut.close();
	out.close();

	return new String(encOut.toByteArray());
}
 
开发者ID:mpw96,项目名称:geocaching,代码行数:38,代码来源:StringEncryptor.java

示例11: writeBytesToLiteralData

import org.bouncycastle.openpgp.PGPLiteralDataGenerator; //导入依赖的package包/类
private static void writeBytesToLiteralData(OutputStream out,
        char fileType, String name, byte[] bytes) throws IOException {
    PGPLiteralDataGenerator lData = new PGPLiteralDataGenerator();
    OutputStream pOut = lData.open(out, fileType, name,
            bytes.length, new Date());
    pOut.write(bytes);
}
 
开发者ID:payneteasy,项目名称:superfly,代码行数:8,代码来源:PGPUtils.java

示例12: bufferTest

import org.bouncycastle.openpgp.PGPLiteralDataGenerator; //导入依赖的package包/类
private void bufferTest(
    PGPLiteralDataGenerator generator, 
    byte[] buf, 
    int i)
    throws IOException
{
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    OutputStream out = generator.open(
        new UncloseableOutputStream(bOut),
        PGPLiteralData.BINARY,
        PGPLiteralData.CONSOLE,
        i,
        new Date());

    out.write(buf, 0, i);
    
    generator.close();
    
    PGPObjectFactory        fact = new PGPObjectFactory(bOut.toByteArray());
    PGPLiteralData          data = (PGPLiteralData)fact.nextObject();
    InputStream             in = data.getInputStream();

    for (int count = 0; count != i; count++)
    {
        if (in.read() != (buf[count] & 0xff))
        {
            fail("failed readback test - length = " + i);
        }
    }
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:31,代码来源:PGPPacketTest.java

示例13: performTest

import org.bouncycastle.openpgp.PGPLiteralDataGenerator; //导入依赖的package包/类
public void performTest()
    throws IOException
{
    PGPLiteralDataGenerator oldGenerator = new PGPLiteralDataGenerator(true);

    readBackTest(oldGenerator);
    
    PGPLiteralDataGenerator newGenerator = new PGPLiteralDataGenerator(false);
    
    readBackTest(newGenerator);
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:12,代码来源:PGPPacketTest.java

示例14: testSig

import org.bouncycastle.openpgp.PGPLiteralDataGenerator; //导入依赖的package包/类
private void testSig(
    int           encAlgorithm,
    int           hashAlgorithm,
    PGPPublicKey  pubKey,
    PGPPrivateKey privKey)
    throws Exception
{            
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    ByteArrayInputStream  testIn = new ByteArrayInputStream(TEST_DATA);
    PGPSignatureGenerator sGen = new PGPSignatureGenerator(new JcaPGPContentSignerBuilder(encAlgorithm, hashAlgorithm).setProvider("BC"));
    
    sGen.init(PGPSignature.BINARY_DOCUMENT, privKey);
    sGen.generateOnePassVersion(false).encode(bOut);

    PGPLiteralDataGenerator    lGen = new PGPLiteralDataGenerator();
    OutputStream               lOut = lGen.open(
        new UncloseableOutputStream(bOut),
        PGPLiteralData.BINARY,
        "_CONSOLE",
        TEST_DATA.length * 2,
        new Date());

    int ch;
    while ((ch = testIn.read()) >= 0)
    {
        lOut.write(ch);
        sGen.update((byte)ch);
    }

    lOut.write(TEST_DATA);
    sGen.update(TEST_DATA);
    
    lGen.close();

    sGen.generate().encode(bOut);

    verifySignature(bOut.toByteArray(), hashAlgorithm, pubKey, TEST_DATA);
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:39,代码来源:PGPSignatureTest.java

示例15: generateV3BinarySig

import org.bouncycastle.openpgp.PGPLiteralDataGenerator; //导入依赖的package包/类
private byte[] generateV3BinarySig(PGPPrivateKey privKey, int encAlgorithm, int hashAlgorithm) 
    throws Exception
{
    ByteArrayOutputStream   bOut = new ByteArrayOutputStream();
    ByteArrayInputStream    testIn = new ByteArrayInputStream(TEST_DATA);
    PGPV3SignatureGenerator sGen = new PGPV3SignatureGenerator(new JcaPGPContentSignerBuilder(encAlgorithm, hashAlgorithm).setProvider("BC"));
    
    sGen.init(PGPSignature.BINARY_DOCUMENT, privKey);
    sGen.generateOnePassVersion(false).encode(bOut);

    PGPLiteralDataGenerator lGen = new PGPLiteralDataGenerator();
    OutputStream            lOut = lGen.open(
        new UncloseableOutputStream(bOut),
        PGPLiteralData.BINARY,
        "_CONSOLE",
        TEST_DATA.length * 2,
        new Date());

    int ch;
    while ((ch = testIn.read()) >= 0)
    {
        lOut.write(ch);
        sGen.update((byte)ch);
    }

    lOut.write(TEST_DATA);
    sGen.update(TEST_DATA);
    
    lGen.close();

    sGen.generate().encode(bOut);
    
    return bOut.toByteArray();
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:35,代码来源:PGPSignatureTest.java


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