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


Java PGPEncryptedDataGenerator类代码示例

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


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

示例1: encrypt

import org.bouncycastle.openpgp.PGPEncryptedDataGenerator; //导入依赖的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: encrypt

import org.bouncycastle.openpgp.PGPEncryptedDataGenerator; //导入依赖的package包/类
/**
 * Wraps with stream that outputs encrypted data packet.
 */
protected OutputStream encrypt(OutputStream out, FileMetadata meta)
throws IOException, PGPException {
    if (log.isLoggable(Level.FINEST))
        log.finest("using encryption algorithm " + encryptionAlgorithm);

    if (encryptionAlgorithm == EncryptionAlgorithm.Unencrypted)
        return null;

    List<Key> keys = ring.getEncryptionKeys();
    if (Util.isEmpty(keys) && Util.isEmpty(symmetricPassphrase))
        throw new PGPException("no suitable encryption key found");

    PGPEncryptedDataGenerator generator = buildEncryptor();
    for (Key key : keys)
        generator.addMethod(buildPublicKeyEncryptor(key));

    if (!Util.isEmpty(symmetricPassphrase))
        generator.addMethod(buildSymmetricKeyEncryptor());

    return generator.open(out, getEncryptionBuffer(meta));
}
 
开发者ID:justinludwig,项目名称:jpgpj,代码行数:25,代码来源:Encryptor.java

示例3: createEncryptedNonCompressedData

import org.bouncycastle.openpgp.PGPEncryptedDataGenerator; //导入依赖的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: main

import org.bouncycastle.openpgp.PGPEncryptedDataGenerator; //导入依赖的package包/类
public static void main(String[] args) throws Exception
{
    Security.addProvider(new BouncyCastleProvider());
    
    String passPhrase = "Dick Beck";
    char[] passArray = passPhrase.toCharArray();

    byte[] original = "Hello world".getBytes();
    System.out.println("Starting PGP test");
    byte[] encrypted = encrypt(original, passArray, "iway", PGPEncryptedDataGenerator.CAST5, true);

    System.out.println("\nencrypted data = '"+new String(encrypted)+"'");
    byte[] decrypted= decrypt(encrypted,passArray);

    System.out.println("\ndecrypted data = '"+new String(decrypted)+"'");
    
    encrypted = encrypt(original, passArray, "iway", PGPEncryptedDataGenerator.AES_256, false);

    System.out.println("\nencrypted data = '"+new String(org.bouncycastle.util.encoders.Hex.encode(encrypted))+"'");
    decrypted= decrypt(encrypted, passArray);

    System.out.println("\ndecrypted data = '"+new String(decrypted)+"'");
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:24,代码来源:ByteArrayHandler.java

示例5: buildEncryptor

import org.bouncycastle.openpgp.PGPEncryptedDataGenerator; //导入依赖的package包/类
/**
 * Builds a PGPEncryptedDataGenerator
 * for the configured encryption algorithm.
 */
protected PGPEncryptedDataGenerator buildEncryptor() {
    int algo = encryptionAlgorithm.ordinal();
    BcPGPDataEncryptorBuilder builder = new BcPGPDataEncryptorBuilder(algo);
    builder.setWithIntegrityPacket(true);
    return new PGPEncryptedDataGenerator(builder);
}
 
开发者ID:justinludwig,项目名称:jpgpj,代码行数:11,代码来源:Encryptor.java

示例6: getEncryptedGenerator

import org.bouncycastle.openpgp.PGPEncryptedDataGenerator; //导入依赖的package包/类
private static PGPEncryptedDataGenerator getEncryptedGenerator( PGPPublicKey publicKey )
{
    PGPEncryptedDataGenerator encGen = new PGPEncryptedDataGenerator(
            new JcePGPDataEncryptorBuilder( PGPEncryptedData.CAST5 ).setWithIntegrityPacket( true )
                                                                    .setSecureRandom( new SecureRandom() )
                                                                    .setProvider( "BC" ) );

    encGen.addMethod( new JcePublicKeyKeyEncryptionMethodGenerator( publicKey ).setProvider( "BC" ) );

    return encGen;
}
 
开发者ID:subutai-io,项目名称:base,代码行数:12,代码来源:PGPEncrypt.java

示例7: encryptFile

import org.bouncycastle.openpgp.PGPEncryptedDataGenerator; //导入依赖的package包/类
/**
* Encrypt the given file 
* @param unencryptedFileName - Name of the unecrypted file
* @param encryptedFileName - Name of the encrypted file, will have .enc as extension
* @throws IOException 
* @throws NoSuchProviderException
* @throws PGPException
* @throws CryptDecryptException 
*/
  public void encryptFile(final String unencryptedFileName, final String encryptedFileName)
      throws IOException, NoSuchProviderException, PGPException, CryptDecryptException {
  	if(enableDebugLog)Trace.logInfo("CryptDecryptUtil.encryptFile", "Entry");

  	// Initialise PGP provider and read public key
  	if(!initialized) initialise(false);

FileOutputStream encrytedFile = new FileOutputStream(encryptedFileName);
        
// Compress the input plain text file in ZIP format.
  	ByteArrayOutputStream bOut = new ByteArrayOutputStream();
      PGPCompressedDataGenerator comData = new PGPCompressedDataGenerator(PGPCompressedData.ZIP);
      PGPUtil.writeFileToLiteralData(comData.open(bOut), PGPLiteralData.BINARY, new File(unencryptedFileName) );
      comData.close();

      // Encrypt the file using Triple-DES algorithm
      BcPGPDataEncryptorBuilder dataEncryptor = new BcPGPDataEncryptorBuilder(PGPEncryptedData.TRIPLE_DES);
      dataEncryptor.setWithIntegrityPacket(false);
      dataEncryptor.setSecureRandom(new SecureRandom());
      PGPEncryptedDataGenerator encryptedDataGenerator = new PGPEncryptedDataGenerator(dataEncryptor);
      encryptedDataGenerator.addMethod(new BcPublicKeyKeyEncryptionMethodGenerator(publicKey));
      byte[] bytes = bOut.toByteArray();
      OutputStream cOut = encryptedDataGenerator.open(encrytedFile, bytes.length);
      cOut.write(bytes);
      cOut.close();
      encrytedFile.close();
      
      if(enableDebugLog)Trace.logInfo("CryptDecryptUtil.encryptFile", "Exit");
  }
 
开发者ID:ibm-messaging,项目名称:mq-mft,代码行数:39,代码来源:CryptDecryptUtil.java

示例8: openEncryptor

import org.bouncycastle.openpgp.PGPEncryptedDataGenerator; //导入依赖的package包/类
/**
 * Opens a new {@link Encryptor} (Writing Step 1/3)
 *
 * <p>This is the first step in creating a ghostryde file. After this method, you'll want to
 * call {@link #openCompressor(Encryptor)}.
 *
 * @param os is the upstream {@link OutputStream} to which the result is written.
 * @param publicKey is the public encryption key of the recipient.
 * @throws IOException
 * @throws PGPException
 */
@CheckReturnValue
public Encryptor openEncryptor(@WillNotClose OutputStream os, PGPPublicKey publicKey)
    throws IOException, PGPException {
  PGPEncryptedDataGenerator encryptor = new PGPEncryptedDataGenerator(
      new JcePGPDataEncryptorBuilder(CIPHER)
         .setWithIntegrityPacket(USE_INTEGRITY_PACKET)
         .setSecureRandom(getRandom())
         .setProvider(PROVIDER_NAME));
  encryptor.addMethod(new BcPublicKeyKeyEncryptionMethodGenerator(publicKey));
  return new Encryptor(encryptor.open(os, new byte[bufferSize]));
}
 
开发者ID:google,项目名称:nomulus,代码行数:23,代码来源:Ghostryde.java

示例9: testEncryptDecrypt_ExplicitStyle

import org.bouncycastle.openpgp.PGPEncryptedDataGenerator; //导入依赖的package包/类
@Test
public void testEncryptDecrypt_ExplicitStyle() throws Exception {
  int bufferSize = 64 * 1024;

  // Alice loads Bob's "publicKey" into memory.
  PGPPublicKeyRing publicKeyRing = new BcPGPPublicKeyRing(PUBLIC_KEY);
  PGPPublicKey publicKey = publicKeyRing.getPublicKey();

  // Alice encrypts the secret message for Bob using his "publicKey".
  PGPEncryptedDataGenerator encryptor = new PGPEncryptedDataGenerator(
      new BcPGPDataEncryptorBuilder(AES_128));
  encryptor.addMethod(new BcPublicKeyKeyEncryptionMethodGenerator(publicKey));
  byte[] encryptedData;
  try (ByteArrayOutputStream output = new ByteArrayOutputStream()) {
    try (OutputStream output2 = encryptor.open(output, new byte[bufferSize])) {
      output2.write(FALL_OF_HYPERION_A_DREAM.getBytes(UTF_8));
    }
    encryptedData = output.toByteArray();
  }
  logger.info("Encrypted data: " + dumpHex(encryptedData));

  // Bob loads his "privateKey" into memory.
  PGPSecretKeyRing privateKeyRing = new BcPGPSecretKeyRing(PRIVATE_KEY);
  PGPPrivateKey privateKey = extractPrivateKey(privateKeyRing.getSecretKey());

  // Bob decrypt's the OpenPGP message (w/ ciphertext) using his "privateKey".
  try (ByteArrayInputStream input = new ByteArrayInputStream(encryptedData)) {
    PGPObjectFactory pgpFact = new BcPGPObjectFactory(input);
    PGPEncryptedDataList encDataList = (PGPEncryptedDataList) pgpFact.nextObject();
    assertThat(encDataList.size()).isEqualTo(1);
    PGPPublicKeyEncryptedData encData = (PGPPublicKeyEncryptedData) encDataList.get(0);
    assertThat(encData.getKeyID()).isEqualTo(publicKey.getKeyID());
    assertThat(encData.getKeyID()).isEqualTo(privateKey.getKeyID());
    try (InputStream original =
        encData.getDataStream(new BcPublicKeyDataDecryptorFactory(privateKey))) {
      assertThat(CharStreams.toString(new InputStreamReader(original, UTF_8)))
          .isEqualTo(FALL_OF_HYPERION_A_DREAM);
    }
  }
}
 
开发者ID:google,项目名称:nomulus,代码行数:41,代码来源:BouncyCastleTest.java

示例10: testExceptionDecryptorIncorrectInputFormatSymmetricEncryptedData

import org.bouncycastle.openpgp.PGPEncryptedDataGenerator; //导入依赖的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

示例11: encryptString

import org.bouncycastle.openpgp.PGPEncryptedDataGenerator; //导入依赖的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

示例12: signAndEncrypt

import org.bouncycastle.openpgp.PGPEncryptedDataGenerator; //导入依赖的package包/类
public static byte[] signAndEncrypt( final byte[] message, final PGPSecretKey secretKey, final String secretPwd,
                                     final PGPPublicKey publicKey, final boolean armored ) throws PGPException
{
    try
    {
        final ByteArrayOutputStream out = new ByteArrayOutputStream();
        final PGPEncryptedDataGenerator encryptedDataGenerator = new PGPEncryptedDataGenerator(
                new JcePGPDataEncryptorBuilder( SymmetricKeyAlgorithmTags.AES_256 ).setWithIntegrityPacket( true )
                                                                                   .setSecureRandom(
                                                                                           new SecureRandom() )
                                                                                   .setProvider( provider ) );

        encryptedDataGenerator.addMethod(
                new JcePublicKeyKeyEncryptionMethodGenerator( publicKey ).setSecureRandom( new SecureRandom() )
                                                                         .setProvider( provider ) );

        final OutputStream theOut = armored ? new ArmoredOutputStream( out ) : out;
        final OutputStream encryptedOut = encryptedDataGenerator.open( theOut, new byte[4096] );

        final PGPCompressedDataGenerator compressedDataGenerator =
                new PGPCompressedDataGenerator( CompressionAlgorithmTags.ZIP );
        final OutputStream compressedOut = compressedDataGenerator.open( encryptedOut, new byte[4096] );
        final PGPPrivateKey privateKey = secretKey.extractPrivateKey(
                new JcePBESecretKeyDecryptorBuilder().setProvider( provider ).build( secretPwd.toCharArray() ) );
        final PGPSignatureGenerator signatureGenerator = new PGPSignatureGenerator(
                new JcaPGPContentSignerBuilder( secretKey.getPublicKey().getAlgorithm(), HashAlgorithmTags.SHA1 )
                        .setProvider( provider ) );
        signatureGenerator.init( PGPSignature.BINARY_DOCUMENT, privateKey );
        final Iterator<?> it = secretKey.getPublicKey().getUserIDs();
        if ( it.hasNext() )
        {
            final PGPSignatureSubpacketGenerator spGen = new PGPSignatureSubpacketGenerator();
            spGen.setSignerUserID( false, ( String ) it.next() );
            signatureGenerator.setHashedSubpackets( spGen.generate() );
        }
        signatureGenerator.generateOnePassVersion( false ).encode( compressedOut );
        final PGPLiteralDataGenerator literalDataGenerator = new PGPLiteralDataGenerator();
        final OutputStream literalOut = literalDataGenerator
                .open( compressedOut, PGPLiteralData.BINARY, "filename", new Date(), new byte[4096] );
        final InputStream in = new ByteArrayInputStream( message );
        final byte[] buf = new byte[4096];
        for ( int len; ( len = in.read( buf ) ) > 0; )
        {
            literalOut.write( buf, 0, len );
            signatureGenerator.update( buf, 0, len );
        }
        in.close();
        literalDataGenerator.close();
        signatureGenerator.generate().encode( compressedOut );
        compressedDataGenerator.close();
        encryptedDataGenerator.close();
        theOut.close();
        return out.toByteArray();
    }
    catch ( Exception e )
    {
        throw new PGPException( "Error in signAndEncrypt", e );
    }
}
 
开发者ID:subutai-io,项目名称:base,代码行数:60,代码来源:PGPEncryptionUtil.java

示例13: testEncryptDecrypt_KeyRingStyle

import org.bouncycastle.openpgp.PGPEncryptedDataGenerator; //导入依赖的package包/类
@Test
public void testEncryptDecrypt_KeyRingStyle() throws Exception {
  int bufferSize = 64 * 1024;

  // Alice loads Bob's "publicKey" into memory from her public key ring.
  PGPPublicKeyRingCollection publicKeyRings = new BcPGPPublicKeyRingCollection(
      PGPUtil.getDecoderStream(new ByteArrayInputStream(PUBLIC_KEY)));
  PGPPublicKeyRing publicKeyRing =
      publicKeyRings.getKeyRings("[email protected]", true, true).next();
  PGPPublicKey publicKey = publicKeyRing.getPublicKey();

  // Alice encrypts the secret message for Bob using his "publicKey".
  PGPEncryptedDataGenerator encryptor = new PGPEncryptedDataGenerator(
      new BcPGPDataEncryptorBuilder(AES_128));
  encryptor.addMethod(new BcPublicKeyKeyEncryptionMethodGenerator(publicKey));
  byte[] encryptedData;
  try (ByteArrayOutputStream output = new ByteArrayOutputStream()) {
    try (OutputStream output2 = encryptor.open(output, new byte[bufferSize])) {
      output2.write(FALL_OF_HYPERION_A_DREAM.getBytes(UTF_8));
    }
    encryptedData = output.toByteArray();
  }
  logger.info("Encrypted data: " + dumpHex(encryptedData));

  // Bob loads his chain of private keys into memory.
  PGPSecretKeyRingCollection privateKeyRings = new BcPGPSecretKeyRingCollection(
      PGPUtil.getDecoderStream(new ByteArrayInputStream(PRIVATE_KEY)));

  // Bob decrypt's the OpenPGP message (w/ ciphertext) using his "privateKey".
  try (ByteArrayInputStream input = new ByteArrayInputStream(encryptedData)) {
    PGPObjectFactory pgpFact = new BcPGPObjectFactory(input);
    PGPEncryptedDataList encDataList = (PGPEncryptedDataList) pgpFact.nextObject();
    assertThat(encDataList.size()).isEqualTo(1);
    PGPPublicKeyEncryptedData encData = (PGPPublicKeyEncryptedData) encDataList.get(0);
    // Bob loads the private key to which the message is addressed.
    PGPPrivateKey privateKey =
        extractPrivateKey(privateKeyRings.getSecretKey(encData.getKeyID()));
    try (InputStream original =
        encData.getDataStream(new BcPublicKeyDataDecryptorFactory(privateKey))) {
      assertThat(CharStreams.toString(new InputStreamReader(original, UTF_8)))
          .isEqualTo(FALL_OF_HYPERION_A_DREAM);
    }
  }
}
 
开发者ID:google,项目名称:nomulus,代码行数:45,代码来源:BouncyCastleTest.java

示例14: signAndEncrypt

import org.bouncycastle.openpgp.PGPEncryptedDataGenerator; //导入依赖的package包/类
@Override
public String signAndEncrypt(String message) throws IOException {
	
	try {
		/* Final < Armored < Crypted < Clear PGP */
		ByteArrayOutputStream out = new ByteArrayOutputStream();
		ArmoredOutputStream armoredOutput = new ArmoredOutputStream(out);
		PGPEncryptedDataGenerator crypter = new PGPEncryptedDataGenerator(PGPEncryptedDataGenerator.S2K_SHA1, new SecureRandom(), _provider);
		crypter.addMethod(getRemotePublicKey());
		BCPGOutputStream pgpOut = new BCPGOutputStream(crypter.open(armoredOutput, new byte[512]));
		
		/* Prepare for signing */
        PGPSignatureGenerator signer = new PGPSignatureGenerator(getSigningPublicKey().getAlgorithm(), 
                PGPUtil.SHA1, _provider
                );
        signer.initSign(PGPSignature.BINARY_DOCUMENT, getSigningPrivateKey());
        
        /* Output the standard header */
        signer.generateOnePassVersion(false).encode(pgpOut);

        /* Output the literal data */
        PGPLiteralDataGenerator literalDataGenerator = new PGPLiteralDataGenerator(true);
        literalDataGenerator.open(pgpOut, 'b', "bar", message.getBytes().length, new Date()).write(message.getBytes());
        
        /* Calculate signature and output it */
        signer.update(message.getBytes());
        signer.generate().encode(pgpOut);

        pgpOut.close();
        armoredOutput.close();
        out.close();
        
        byte[] result = out.toByteArray();
        
        // brain dead UMAPI adds an extra base64 encoding on top of the ASCII armored string. Go figure.
		return new String(Base64.encode(result));
		
	} catch (PGPException pgpException) {
		throw new IOException("PGP subsystem problem.", pgpException);
		
	} catch (NoSuchAlgorithmException noSuchAlgorithmException) {
		throw new IOException("Missing algorithm. Are you running a compatible JVM/Bouncycastle version?", noSuchAlgorithmException);
		
	} catch (SignatureException signatureException) {
		throw new IOException("PGP subsystem problem.", signatureException);
		
	} catch (NoSuchProviderException noSuchProviderException) {
		throw new IOException("Missing provider. Are you running a compatible JVM/Bouncycastle version?", noSuchProviderException);
		
	}
	
	
}
 
开发者ID:neopeak,项目名称:brownsocks-payments-enets,代码行数:54,代码来源:BCPGPProvider.java

示例15: createEncryptedDataGenerator

import org.bouncycastle.openpgp.PGPEncryptedDataGenerator; //导入依赖的package包/类
private PGPEncryptedDataGenerator createEncryptedDataGenerator() {
	return new PGPEncryptedDataGenerator(
			new BcPGPDataEncryptorBuilder(getSymmetricEncryptionAlgorithm().getSymmetricKeyAlgorithmTag())
			.setWithIntegrityPacket(isWithIntegrityCheck())
			.setSecureRandom(new SecureRandom()));
}
 
开发者ID:subshare,项目名称:subshare,代码行数:7,代码来源:BcPgpEncoder.java


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