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


Java PGPSignatureGenerator.init方法代码示例

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


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

示例1: signArmoredAscii

import org.bouncycastle.openpgp.PGPSignatureGenerator; //导入方法依赖的package包/类
static String signArmoredAscii(PGPPrivateKey privateKey, String data, int signatureAlgo) throws IOException, PGPException {
  String signature = null;
  final PGPSignatureGenerator signatureGenerator = new PGPSignatureGenerator(new BcPGPContentSignerBuilder(privateKey.getPublicKeyPacket().getAlgorithm(), signatureAlgo));
  signatureGenerator.init(PGPSignature.BINARY_DOCUMENT, privateKey);
  ByteArrayOutputStream signatureOutput = new ByteArrayOutputStream();
  try( BCPGOutputStream outputStream = new BCPGOutputStream( new ArmoredOutputStream(signatureOutput)) ) {
    Utils.processStringAsStream(data, new StreamHandler() {
      @Override
      public void handleStreamBuffer(byte[] buffer, int offset, int length) throws IOException {
        signatureGenerator.update(buffer, offset, length);
      }
    });
    signatureGenerator.generate().encode(outputStream);
  }

  signature = new String(signatureOutput.toByteArray(), "UTF-8");

  return signature;
}
 
开发者ID:quan-to,项目名称:react-native-pgp,代码行数:20,代码来源:PGPUtils.java

示例2: signExternal

import org.bouncycastle.openpgp.PGPSignatureGenerator; //导入方法依赖的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.PGPSignatureGenerator; //导入方法依赖的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: createSignatureGenerator

import org.bouncycastle.openpgp.PGPSignatureGenerator; //导入方法依赖的package包/类
public PGPSignatureGenerator createSignatureGenerator() {
    try {
        PGPSignatureGenerator generator = new PGPSignatureGenerator(new BcPGPContentSignerBuilder(secretKey.getPublicKey().getAlgorithm(), PGPUtil.SHA1));
        generator.init(PGPSignature.BINARY_DOCUMENT, privateKey);
        return generator;
    } catch (PGPException e) {
        throw new UncheckedException(e);
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:10,代码来源:PgpSignatory.java

示例5: buildSigner

import org.bouncycastle.openpgp.PGPSignatureGenerator; //导入方法依赖的package包/类
/**
 * Builds a PGPSignatureGenerator for the specified key and content.
 */
protected PGPSignatureGenerator buildSigner(Key key, FileMetadata meta)
throws PGPException {
    Subkey subkey = key.getSigning();

    if (log.isLoggable(Level.INFO))
        log.info("using signing key " + subkey);

    PGPContentSignerBuilder builder = buildSignerBuilder(
        subkey.getPublicKey().getAlgorithm(),
        signingAlgorithm.ordinal()
    );

    PGPSignatureGenerator generator = new PGPSignatureGenerator(builder);
    generator.init(meta.getSignatureType(), subkey.getPrivateKey());

    String uid = key.getSigningUid();
    if (!Util.isEmpty(uid)) {
        if (log.isLoggable(Level.FINE))
            log.fine("using signing uid " + uid);

        PGPSignatureSubpacketGenerator signer =
            new PGPSignatureSubpacketGenerator();
        signer.setSignerUserID(false, uid);
        generator.setHashedSubpackets(signer.generate());
    }

    return generator;
}
 
开发者ID:justinludwig,项目名称:jpgpj,代码行数:32,代码来源:Encryptor.java

示例6: signPublicKey

import org.bouncycastle.openpgp.PGPSignatureGenerator; //导入方法依赖的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.PGPSignatureGenerator; //导入方法依赖的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: RydePgpSigningOutputStream

import org.bouncycastle.openpgp.PGPSignatureGenerator; //导入方法依赖的package包/类
/**
 * Create a signer that wraps {@code os} and generates a detached signature using
 * {@code signingKey}. After closing, you should call {@link #getSignature()} to get the detached
 * signature.
 *
 * @param os is the upstream {@link OutputStream} which is not closed by this object
 * @throws RuntimeException to rethrow {@link PGPException}
 */
public RydePgpSigningOutputStream(
    @WillNotClose OutputStream os,
    PGPKeyPair signingKey) {
  super(os, false, -1);
  try {
    signer = new PGPSignatureGenerator(
        new BcPGPContentSignerBuilder(RSA_GENERAL, SHA256));
    signer.init(BINARY_DOCUMENT, signingKey.getPrivateKey());
  } catch (PGPException e) {
    throw new RuntimeException(e);
  }
  addUserInfoToSignature(signingKey.getPublicKey(), signer);
}
 
开发者ID:google,项目名称:nomulus,代码行数:22,代码来源:RydePgpSigningOutputStream.java

示例9: testSignVerify_Detached

import org.bouncycastle.openpgp.PGPSignatureGenerator; //导入方法依赖的package包/类
@Test
public void testSignVerify_Detached() throws Exception {
  // Load the keys.
  PGPPublicKeyRing publicKeyRing = new BcPGPPublicKeyRing(PUBLIC_KEY);
  PGPSecretKeyRing privateKeyRing = new BcPGPSecretKeyRing(PRIVATE_KEY);
  PGPPublicKey publicKey = publicKeyRing.getPublicKey();
  PGPPrivateKey privateKey = extractPrivateKey(privateKeyRing.getSecretKey());

  // Sign the data and write signature data to "signatureFile".
  // Note: RSA_GENERAL will encrypt AND sign. RSA_SIGN and RSA_ENCRYPT are deprecated.
  PGPSignatureGenerator signer = new PGPSignatureGenerator(
      new BcPGPContentSignerBuilder(RSA_GENERAL, SHA256));
  signer.init(PGPSignature.BINARY_DOCUMENT, privateKey);
  addUserInfoToSignature(publicKey, signer);
  signer.update(FALL_OF_HYPERION_A_DREAM.getBytes(UTF_8));
  ByteArrayOutputStream output = new ByteArrayOutputStream();
  signer.generate().encode(output);
  byte[] signatureFileData = output.toByteArray();
  logger.info(".sig file data: " + dumpHex(signatureFileData));

  // Load algorithm information and signature data from "signatureFileData".
  PGPSignature sig;
  try (ByteArrayInputStream input = new ByteArrayInputStream(signatureFileData)) {
    PGPObjectFactory pgpFact = new BcPGPObjectFactory(input);
    PGPSignatureList sigList = (PGPSignatureList) pgpFact.nextObject();
    assertThat(sigList.size()).isEqualTo(1);
    sig = sigList.get(0);
  }

  // Use "onePass" and "sig" to verify "publicKey" signed the text.
  sig.init(new BcPGPContentVerifierBuilderProvider(), publicKey);
  sig.update(FALL_OF_HYPERION_A_DREAM.getBytes(UTF_8));
  assertThat(sig.verify()).isTrue();

  // Verify that they DIDN'T sign the text "hello monster".
  sig.init(new BcPGPContentVerifierBuilderProvider(), publicKey);
  sig.update("hello monster".getBytes(UTF_8));
  assertThat(sig.verify()).isFalse();
}
 
开发者ID:google,项目名称:nomulus,代码行数:40,代码来源:BouncyCastleTest.java

示例10: signInline

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

示例11: createSignatureGenerator

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

示例12: feedHeader

import org.bouncycastle.openpgp.PGPSignatureGenerator; //导入方法依赖的package包/类
@Override
public void feedHeader ( final ByteBuffer header )
{
    try
    {
        final BcPGPContentSignerBuilder contentSignerBuilder = new BcPGPContentSignerBuilder ( this.privateKey.getPublicKeyPacket ().getAlgorithm (), this.hashAlgorithm );
        final PGPSignatureGenerator signatureGenerator = new PGPSignatureGenerator ( contentSignerBuilder );

        signatureGenerator.init ( PGPSignature.BINARY_DOCUMENT, this.privateKey );

        if ( header.hasArray () )
        {
            signatureGenerator.update ( header.array (), header.position (), header.remaining () );
        }
        else
        {
            final byte[] buffer = new byte[header.remaining ()];
            header.get ( buffer );
            signatureGenerator.update ( buffer );
        }

        this.value = signatureGenerator.generate ().getEncoded ();
        logger.info ( "RSA HEADER: {}", this.value );
    }
    catch ( final Exception e )
    {
        throw new RuntimeException ( e );
    }
}
 
开发者ID:eclipse,项目名称:packagedrone,代码行数:30,代码来源:RsaHeaderSignatureProcessor.java

示例13: addUserId

import org.bouncycastle.openpgp.PGPSignatureGenerator; //导入方法依赖的package包/类
private static PGPPublicKeyRing addUserId(
		final PGPPublicKeyRing publicKeyRing, final String userId,
		final PGPSecretKeyRing secretKeyRing,
		final char[] passphrase,
		PGPContentSignerBuilder signerBuilder,
		final PGPSignatureSubpacketVector hashedSubpackets,
		final PGPSignatureSubpacketVector unhashedSubpackets) throws PGPException {
	assertNotNull(publicKeyRing, "publicKeyRing");
	assertNotNull(userId, "userId");

	final PGPPublicKey masterPublicKey = getMasterKeyOrFail(publicKeyRing);
	final PGPSecretKey masterSecretKey = secretKeyRing.getSecretKey(masterPublicKey.getKeyID());
	assertNotNull(masterSecretKey, "masterSecretKey");
	final PGPPrivateKey privateKey = extractPrivateKey(masterSecretKey, passphrase);

	final PGPSignatureGenerator sGen = new PGPSignatureGenerator(signerBuilder);

	sGen.init(PGPSignature.POSITIVE_CERTIFICATION, privateKey);

	sGen.setHashedSubpackets(hashedSubpackets);
	sGen.setUnhashedSubpackets(unhashedSubpackets);

	final PGPSignature certification = sGen.generateCertification(userId, masterPublicKey);
	final PGPPublicKey newMasterPublicKey = PGPPublicKey.addCertification(masterPublicKey, userId, certification);

	PGPPublicKeyRing result = PGPPublicKeyRing.removePublicKey(publicKeyRing, masterPublicKey);
	result = PGPPublicKeyRing.insertPublicKey(result, newMasterPublicKey);
	return result;
}
 
开发者ID:subshare,项目名称:subshare,代码行数:30,代码来源:BcWithLocalGnuPgPgp.java

示例14: OpenPGPSignature

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

示例15: sign

import org.bouncycastle.openpgp.PGPSignatureGenerator; //导入方法依赖的package包/类
@Override
public void sign ( final InputStream in, final OutputStream out, final boolean inline ) throws Exception
{
    final int digest = HashAlgorithmTags.SHA1;
    final PGPSignatureGenerator signatureGenerator = new PGPSignatureGenerator ( new BcPGPContentSignerBuilder ( this.privateKey.getPublicKeyPacket ().getAlgorithm (), digest ) );
    signatureGenerator.init ( PGPSignature.BINARY_DOCUMENT, this.privateKey );

    final ArmoredOutputStream armoredOutput = new ArmoredOutputStream ( out );

    if ( inline )
    {
        armoredOutput.beginClearText ( digest );
    }

    final byte[] buffer = new byte[4096];

    int rc;
    while ( ( rc = in.read ( buffer ) ) >= 0 )
    {
        if ( inline )
        {
            armoredOutput.write ( buffer, 0, rc );
        }
        signatureGenerator.update ( buffer, 0, rc );
    }

    armoredOutput.endClearText ();

    final PGPSignature signature = signatureGenerator.generate ();
    signature.encode ( new BCPGOutputStream ( armoredOutput ) );

    armoredOutput.close ();
}
 
开发者ID:ctron,项目名称:package-drone,代码行数:34,代码来源:PgpSigningService.java


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