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


Java JcaPGPContentSignerBuilder类代码示例

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


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

示例1: createPGPKeyRingGenerator

import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder; //导入依赖的package包/类
/**
 * 
 * @param dsaKeyPair - the generated DSA key pair
 * @param elGamalKeyPair - the generated El Gamal key pair
 * @param identity - the given identity of the key pair ring
 * @param passphrase - the secret pass phrase to protect the key pair
 * @return a PGP Key Ring Generate with the El Gamal key pair added as sub key
 * @throws Exception
 */
public static final PGPKeyRingGenerator createPGPKeyRingGenerator(KeyPair dsaKeyPair, KeyPair elGamalKeyPair, String identity, char[] passphrase) throws Exception {
        PGPKeyPair dsaPgpKeyPair = new JcaPGPKeyPair(PGPPublicKey.DSA, dsaKeyPair, new Date());
        PGPKeyPair elGamalPgpKeyPair = new JcaPGPKeyPair(PGPPublicKey.ELGAMAL_ENCRYPT, elGamalKeyPair, new Date());
        PGPDigestCalculator sha1Calc = new JcaPGPDigestCalculatorProviderBuilder().build().get(HashAlgorithmTags.SHA1);

        PGPKeyRingGenerator keyRingGen = new PGPKeyRingGenerator(
                        PGPSignature.POSITIVE_CERTIFICATION,
                        dsaPgpKeyPair,
                        identity,
                        sha1Calc,
                        null,
                        null,
                        new JcaPGPContentSignerBuilder(dsaPgpKeyPair.getPublicKey().getAlgorithm(), HashAlgorithmTags.SHA1),
                        new JcePBESecretKeyEncryptorBuilder(PGPEncryptedData.AES_256, sha1Calc).setProvider("BC").build(passphrase)
                        );

        keyRingGen.addSubKey(elGamalPgpKeyPair);
        return keyRingGen;
}
 
开发者ID:george-haddad,项目名称:bouncycastle,代码行数:29,代码来源:PGPKeyTools.java

示例2: signExternal

import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder; //导入依赖的package包/类
public byte[] signExternal(String input) throws IOException, PGPException {
  PGPSecretKey signKey = readSecretKey();
  PGPPrivateKey privKey = signKey.extractPrivateKey(
      new JcePBESecretKeyDecryptorBuilder().setProvider("BC").build(config.passphrase.toCharArray()));
  PGPSignatureGenerator sigGenerator = new PGPSignatureGenerator(
      new JcaPGPContentSignerBuilder(signKey.getPublicKey().getAlgorithm(), PGPUtil.SHA256).setProvider("BC"));
  sigGenerator.init(PGPSignature.BINARY_DOCUMENT, privKey);

  ByteArrayOutputStream buffer = new ByteArrayOutputStream();

  try (ArmoredOutputStream aOut = new ArmoredOutputStream(buffer)) {
    BCPGOutputStream bOut = new BCPGOutputStream(aOut);
    sigGenerator.update(input.getBytes(Charsets.UTF_8));
    sigGenerator.generate().encode(bOut);
  }

  return buffer.toByteArray();
}
 
开发者ID:sonatype-nexus-community,项目名称:nexus-repository-apt,代码行数:19,代码来源:AptSigningFacet.java

示例3: createSignature

import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder; //导入依赖的package包/类
private void createSignature(OutputStream out) throws Exception {
    PGPSecretKey pgpSec = readSecretKey();
    PGPPrivateKey pgpPrivKey = pgpSec.extractPrivateKey(new JcePBESecretKeyDecryptorBuilder().setProvider(getProvider()).build(
            "sdude".toCharArray()));
    PGPSignatureGenerator sGen = new PGPSignatureGenerator(new JcaPGPContentSignerBuilder(pgpSec.getPublicKey().getAlgorithm(),
            HashAlgorithmTags.SHA1).setProvider(getProvider()));

    sGen.init(PGPSignature.BINARY_DOCUMENT, pgpPrivKey);

    BCPGOutputStream bOut = new BCPGOutputStream(out);

    InputStream fIn = new ByteArrayInputStream("Test Signature".getBytes("UTF-8"));

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

    fIn.close();

    sGen.generate().encode(bOut);

}
 
开发者ID:HydAu,项目名称:Camel,代码行数:24,代码来源:PGPDataFormatTest.java

示例4: PGPSecretKey

import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder; //导入依赖的package包/类
/**
    * @deprecated use method taking PBESecretKeyEncryptor
 */
public PGPSecretKey(
    int                         certificationLevel,
    PGPKeyPair                  keyPair,
    String                      id,
    int                         encAlgorithm,
    char[]                      passPhrase,
    boolean                     useSHA1,
    PGPSignatureSubpacketVector hashedPcks,
    PGPSignatureSubpacketVector unhashedPcks,
    SecureRandom                rand,
    Provider                    provider)
    throws PGPException
{
    this(keyPair.getPrivateKey(), certifiedPublicKey(certificationLevel, keyPair, id, hashedPcks, unhashedPcks, new JcaPGPContentSignerBuilder(keyPair.getPublicKey().getAlgorithm(), HashAlgorithmTags.SHA1).setProvider(provider)), convertSHA1Flag(useSHA1), true, new JcePBESecretKeyEncryptorBuilder(encAlgorithm, new JcaPGPDigestCalculatorProviderBuilder().build().get(HashAlgorithmTags.SHA1)).setProvider(provider).setSecureRandom(rand).build(passPhrase));
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:19,代码来源:PGPSecretKey.java

示例5: PGPKeyRingGenerator

import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder; //导入依赖的package包/类
/**
 * Create a new key ring generator.
 *
 * @param certificationLevel the certification level for keys on this ring.
 * @param masterKey the master key pair.
 * @param id the id to be associated with the ring.
 * @param encAlgorithm the algorithm to be used to protect secret keys.
 * @param passPhrase the passPhrase to be used to protect secret keys.
 * @param useSHA1 checksum the secret keys with SHA1 rather than the older 16 bit checksum.
 * @param hashedPcks packets to be included in the certification hash.
 * @param unhashedPcks packets to be attached unhashed to the certification.
 * @param rand input secured random
 * @param provider the provider to use for encryption.
 *
 * @throws PGPException
 * @throws NoSuchProviderException
 * @deprecated  use method taking PBESecretKeyEncryptor
 */
public PGPKeyRingGenerator(
    int                            certificationLevel,
    PGPKeyPair                     masterKey,
    String                         id,
    int                            encAlgorithm,
    char[]                         passPhrase,
    boolean                        useSHA1,
    PGPSignatureSubpacketVector    hashedPcks,
    PGPSignatureSubpacketVector    unhashedPcks,
    SecureRandom                   rand,
    Provider                       provider)
    throws PGPException, NoSuchProviderException
{
    this.masterKey = masterKey;
    this.hashedPcks = hashedPcks;
    this.unhashedPcks = unhashedPcks;
    this.keyEncryptor = new JcePBESecretKeyEncryptorBuilder(encAlgorithm).setProvider(provider).setSecureRandom(rand).build(passPhrase);
    this.checksumCalculator = convertSHA1Flag(useSHA1);
    this.keySignerBuilder = new JcaPGPContentSignerBuilder(masterKey.getPublicKey().getAlgorithm(), HashAlgorithmTags.SHA1);

    keys.add(new PGPSecretKey(certificationLevel, masterKey, id, checksumCalculator, hashedPcks, unhashedPcks, keySignerBuilder, keyEncryptor));
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:41,代码来源:PGPKeyRingGenerator.java

示例6: signPublicKey

import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder; //导入依赖的package包/类
/**
 * Signs a public key
 *
 * @param publicKeyRing a public key ring containing the single public key to sign
 * @param id the id we are certifying against the public key
 * @param secretKey the signing key
 * @param secretKeyPassword the signing key password
 *
 * @return a public key ring with the signed public key
 */
public static PGPPublicKeyRing signPublicKey( PGPPublicKeyRing publicKeyRing, String id, PGPSecretKey secretKey,
                                              String secretKeyPassword ) throws PGPException
{
    try
    {
        PGPPublicKey oldKey = publicKeyRing.getPublicKey();

        PGPPrivateKey pgpPrivKey = secretKey.extractPrivateKey(
                new JcePBESecretKeyDecryptorBuilder().setProvider( provider )
                                                     .build( secretKeyPassword.toCharArray() ) );

        PGPSignatureGenerator signatureGenerator = new PGPSignatureGenerator(
                new JcaPGPContentSignerBuilder( secretKey.getPublicKey().getAlgorithm(), PGPUtil.SHA1 ) );

        signatureGenerator.init( PGPSignature.DEFAULT_CERTIFICATION, pgpPrivKey );

        PGPSignature signature = signatureGenerator.generateCertification( id, oldKey );

        PGPPublicKey newKey = PGPPublicKey.addCertification( oldKey, signature );

        PGPPublicKeyRing newPublicKeyRing = PGPPublicKeyRing.removePublicKey( publicKeyRing, oldKey );

        return PGPPublicKeyRing.insertPublicKey( newPublicKeyRing, newKey );
    }
    catch ( Exception e )
    {
        //throw custom  exception
        throw new PGPException( "Error signing public key", e );
    }
}
 
开发者ID:subutai-io,项目名称:base,代码行数:41,代码来源:PGPEncryptionUtil.java

示例7: getSignatureGenerator

import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder; //导入依赖的package包/类
private static PGPSignatureGenerator getSignatureGenerator( PGPPrivateKey privateKey, BCPGOutputStream bcOut )
        throws PGPException, IOException
{
    PGPSignatureGenerator signGen = new PGPSignatureGenerator(
            new JcaPGPContentSignerBuilder( privateKey.getPublicKeyPacket().getAlgorithm(), PGPUtil.SHA1 )
                    .setProvider( "BC" ) );

    signGen.init( PGPSignature.BINARY_DOCUMENT, privateKey );

    signGen.generateOnePassVersion( false ).encode( bcOut );

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

示例8: signInline

import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder; //导入依赖的package包/类
public byte[] signInline(String input) throws IOException, PGPException {
  PGPSecretKey signKey = readSecretKey();
  PGPPrivateKey privKey = signKey.extractPrivateKey(
      new JcePBESecretKeyDecryptorBuilder().setProvider("BC").build(config.passphrase.toCharArray()));
  PGPSignatureGenerator sigGenerator = new PGPSignatureGenerator(
      new JcaPGPContentSignerBuilder(signKey.getPublicKey().getAlgorithm(), PGPUtil.SHA256).setProvider("BC"));
  sigGenerator.init(PGPSignature.CANONICAL_TEXT_DOCUMENT, privKey);

  @SuppressWarnings("unchecked")
  Iterator<String> userIds = signKey.getUserIDs();
  if (userIds.hasNext()) {
    PGPSignatureSubpacketGenerator sigSubpacketGenerator = new PGPSignatureSubpacketGenerator();
    sigSubpacketGenerator.setSignerUserID(false, userIds.next());
    sigGenerator.setHashedSubpackets(sigSubpacketGenerator.generate());
  }

  String[] lines = input.split("\r?\n");
  ByteArrayOutputStream buffer = new ByteArrayOutputStream();
  try (ArmoredOutputStream aOut = new ArmoredOutputStream(buffer)) {
    aOut.beginClearText(PGPUtil.SHA256);

    boolean firstLine = true;
    for (String line : lines) {
      String sigLine = (firstLine ? "" : "\r\n") + line.replaceAll("\\s*$", "");
      sigGenerator.update(sigLine.getBytes(Charsets.UTF_8));
      aOut.write((line + "\n").getBytes(Charsets.UTF_8));
      firstLine = false;
    }
    aOut.endClearText();

    BCPGOutputStream bOut = new BCPGOutputStream(aOut);
    sigGenerator.generate().encode(bOut);
  }
  return buffer.toByteArray();
}
 
开发者ID:sonatype-nexus-community,项目名称:nexus-repository-apt,代码行数:36,代码来源:AptSigningFacet.java

示例9: createSignatureGenerator

import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder; //导入依赖的package包/类
protected List<PGPSignatureGenerator> createSignatureGenerator(Exchange exchange, OutputStream out) throws Exception { //NOPMD

        if (secretKeyAccessor == null) {
            return null;
        }

        List<String> sigKeyUserids = determineSignaturenUserIds(exchange);
        List<PGPSecretKeyAndPrivateKeyAndUserId> sigSecretKeysWithPrivateKeyAndUserId = secretKeyAccessor.getSignerKeys(exchange,
                sigKeyUserids);
        if (sigSecretKeysWithPrivateKeyAndUserId.isEmpty()) {
            return null;
        }

        exchange.getOut().setHeader(NUMBER_OF_SIGNING_KEYS, Integer.valueOf(sigSecretKeysWithPrivateKeyAndUserId.size()));

        List<PGPSignatureGenerator> sigGens = new ArrayList<PGPSignatureGenerator>();
        for (PGPSecretKeyAndPrivateKeyAndUserId sigSecretKeyWithPrivateKeyAndUserId : sigSecretKeysWithPrivateKeyAndUserId) {
            PGPPrivateKey sigPrivateKey = sigSecretKeyWithPrivateKeyAndUserId.getPrivateKey();

            PGPSignatureSubpacketGenerator spGen = new PGPSignatureSubpacketGenerator();
            spGen.setSignerUserID(false, sigSecretKeyWithPrivateKeyAndUserId.getUserId());

            int algorithm = sigSecretKeyWithPrivateKeyAndUserId.getSecretKey().getPublicKey().getAlgorithm();
            PGPSignatureGenerator sigGen = new PGPSignatureGenerator(
                    new JcaPGPContentSignerBuilder(algorithm, findHashAlgorithm(exchange)).setProvider(getProvider()));
            sigGen.init(PGPSignature.BINARY_DOCUMENT, sigPrivateKey);
            sigGen.setHashedSubpackets(spGen.generate());
            sigGen.generateOnePassVersion(false).encode(out);
            sigGens.add(sigGen);
        }
        return sigGens;
    }
 
开发者ID:HydAu,项目名称:Camel,代码行数:33,代码来源:PGPKeyAccessDataFormat.java

示例10: OpenPGPSignature

import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder; //导入依赖的package包/类
public OpenPGPSignature(OpenPGPSecretKey key) throws PGPException {
	PGPDigestCalculatorProvider pgpDigestCalculator = new JcaPGPDigestCalculatorProviderBuilder().setProvider(BouncyCastleProvider.PROVIDER_NAME).build();
	PBESecretKeyDecryptor pbeSecretKeyDecryptor = new JcePBESecretKeyDecryptorBuilder(pgpDigestCalculator).setProvider(BouncyCastleProvider.PROVIDER_NAME).build(key.getPassword());
	JcaPGPContentSignerBuilder pgpContentSigner = new JcaPGPContentSignerBuilder(key.getSecretKey().getPublicKey().getAlgorithm(), HashAlgorithmTags.SHA1).setProvider(BouncyCastleProvider.PROVIDER_NAME).setDigestProvider(BouncyCastleProvider.PROVIDER_NAME);

	signature = new PGPSignatureGenerator(pgpContentSigner);

	PGPPrivateKey privateKey = key.getSecretKey().extractPrivateKey(pbeSecretKeyDecryptor);
	signature.init(PGPSignature.BINARY_DOCUMENT, privateKey);
}
 
开发者ID:rednoah,项目名称:ant-spk,代码行数:11,代码来源:OpenPGPSignature.java

示例11: PGPV3SignatureGenerator

import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder; //导入依赖的package包/类
/**
 *
 * @param keyAlgorithm
 * @param hashAlgorithm
 * @param provider
 * @throws NoSuchAlgorithmException
 * @throws PGPException
 * @deprecated use constructor taking PGPContentSignerBuilder.
 */
public PGPV3SignatureGenerator(
    int      keyAlgorithm,
    int      hashAlgorithm,
    Provider provider)
    throws NoSuchAlgorithmException, PGPException
{
    this.providedKeyAlgorithm = keyAlgorithm;
    this.contentSignerBuilder = new JcaPGPContentSignerBuilder(keyAlgorithm, hashAlgorithm).setProvider(provider);
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:19,代码来源:PGPV3SignatureGenerator.java

示例12: PGPSignatureGenerator

import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder; //导入依赖的package包/类
/**
 *
 * @param keyAlgorithm
 * @param sigProvider
 * @param hashAlgorithm
 * @param digProvider
 * @throws NoSuchAlgorithmException
 * @throws PGPException
 * @deprecated use constructor taking PGPContentSignerBuilder.
 */
public PGPSignatureGenerator(
    int      keyAlgorithm,
    Provider sigProvider,
    int      hashAlgorithm,
    Provider digProvider)
    throws NoSuchAlgorithmException, PGPException
{
    this.providedKeyAlgorithm = keyAlgorithm;
    this.contentSignerBuilder = new JcaPGPContentSignerBuilder(keyAlgorithm, hashAlgorithm).setProvider(sigProvider).setDigestProvider(digProvider);
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:21,代码来源:PGPSignatureGenerator.java

示例13: testSig

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

示例14: generateV3BinarySig

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

示例15: EncryptAndSign

import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder; //导入依赖的package包/类
public void EncryptAndSign(OutputStream outputStream, String unencryptedFilename, boolean withArmor, boolean withIntegrityCheck)
        throws IOException, NoSuchProviderException {

    File unencryptedFile = new File(unencryptedFilename);

    if (outputStream == null)
        throw new IllegalArgumentException("outputStream is null");
    if (unencryptedFilename == null || unencryptedFilename.isEmpty())
        throw new IllegalArgumentException("Unencrypted filename is missing");
    if (!unencryptedFile.exists())
        throw new IllegalArgumentException("Unencrypted file is missing");

    if (withArmor) {
        outputStream = new ArmoredOutputStream(outputStream);
    }

    try {
        //SIGNATURE GENERATION OBJECTS
        PGPSignatureGenerator pgpSignatureGenerator = new PGPSignatureGenerator(new JcaPGPContentSignerBuilder(encryptionKeys.getPublicKey().getAlgorithm(), sigHashAlgorithmTag).setProvider("BC"));
        pgpSignatureGenerator.init(PGPSignature.BINARY_DOCUMENT, encryptionKeys.getPrivateKey());

        Iterator it = encryptionKeys.getPublicKey().getUserIDs();
        if (it.hasNext())
        {
            PGPSignatureSubpacketGenerator  signatureSubpacketGenerator = new PGPSignatureSubpacketGenerator();

            signatureSubpacketGenerator.setSignerUserID(false, (String)it.next());
            pgpSignatureGenerator.setHashedSubpackets(signatureSubpacketGenerator.generate());
        }

        //ENCRYPTED GENERATOR OBJECTS
        PGPEncryptedDataGenerator encryptedDataGenerator = new PGPEncryptedDataGenerator(new JcePGPDataEncryptorBuilder(symmetricAlgorithm).setWithIntegrityPacket(withIntegrityCheck).setSecureRandom(new SecureRandom()).setProvider("BC"));

        encryptedDataGenerator.addMethod(new JcePublicKeyKeyEncryptionMethodGenerator(encryptionKeys.getPublicKey()).setProvider("BC"));

        OutputStream encryptedOut = encryptedDataGenerator.open(outputStream, new byte[1 << 16]);

        //COMPRESSED GENERATOR OBJECTS            
        PGPCompressedDataGenerator compressedDataGenerator = new PGPCompressedDataGenerator(
                compressionAlgorithm);

        OutputStream compressedOut = compressedDataGenerator.open(encryptedOut);

        BCPGOutputStream bcpgOutputStream = new BCPGOutputStream(compressedOut);

        pgpSignatureGenerator.generateOnePassVersion(false).encode(bcpgOutputStream);

        //LITERAL DATA GENERATOR OBJECTS
        PGPLiteralDataGenerator literalDataGenerator = new PGPLiteralDataGenerator();

        OutputStream literalOut = literalDataGenerator.open(bcpgOutputStream, PGPLiteralData.BINARY, unencryptedFile);
        FileInputStream in = new FileInputStream(unencryptedFile);

        int ch;
        while ((ch = in.read()) > 0)
        {
            literalOut.write(ch);
            pgpSignatureGenerator.update((byte)ch);
        }

        pgpSignatureGenerator.generate().encode(bcpgOutputStream);

        literalOut.close();
        bcpgOutputStream.close();
        in.close();

        compressedDataGenerator.close();

        encryptedOut.close();
        compressedOut.close();

        if (withArmor) {
            outputStream.close();
        }
    } catch (PGPException e) {
        System.err.println(e);
        if (e.getUnderlyingException() != null) {
            e.getUnderlyingException().printStackTrace();
        }
    }
}
 
开发者ID:GregorySoto,项目名称:pgp-encryption-using-java,代码行数:82,代码来源:PgpEncrypt.java


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