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


Java PGPSecretKeyRingCollection类代码示例

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


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

示例1: getSecretKey

import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; //导入依赖的package包/类
static PGPSecretKey getSecretKey(String privateKeyData) throws IOException, PGPException {
  PGPPrivateKey privKey = null;
  try (InputStream privStream = new ArmoredInputStream(new ByteArrayInputStream(privateKeyData.getBytes("UTF-8")))) {
    PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection(PGPUtil.getDecoderStream(privStream), new JcaKeyFingerprintCalculator());
    Iterator keyRingIter = pgpSec.getKeyRings();
    while (keyRingIter.hasNext()) {
      PGPSecretKeyRing keyRing = (PGPSecretKeyRing)keyRingIter.next();
      Iterator keyIter = keyRing.getSecretKeys();
      while (keyIter.hasNext()) {
        PGPSecretKey key = (PGPSecretKey)keyIter.next();

        if (key.isSigningKey()) {
          return key;
        }
      }
    }
  }
  throw new IllegalArgumentException("Can't find signing key in key ring.");
}
 
开发者ID:quan-to,项目名称:react-native-pgp,代码行数:20,代码来源:PGPUtils.java

示例2: asLiteral

import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; //导入依赖的package包/类
private static PGPLiteralData asLiteral( final byte[] message, final InputStream secretKeyRing,
                                         final String secretPwd ) throws IOException, PGPException
{
    PGPPrivateKey key = null;
    PGPPublicKeyEncryptedData encrypted = null;
    final PGPSecretKeyRingCollection keys =
            new PGPSecretKeyRingCollection( PGPUtil.getDecoderStream( secretKeyRing ),
                    new JcaKeyFingerprintCalculator() );
    for ( final Iterator<PGPPublicKeyEncryptedData> i = getEncryptedObjects( message );
          ( key == null ) && i.hasNext(); )
    {
        encrypted = i.next();
        key = getPrivateKey( keys, encrypted.getKeyID(), secretPwd );
    }
    if ( key == null )
    {
        throw new IllegalArgumentException( "secret key for message not found." );
    }
    final InputStream stream = encrypted
            .getDataStream( new JcePublicKeyDataDecryptorFactoryBuilder().setProvider( provider ).build( key ) );
    return asLiteral( stream );
}
 
开发者ID:subutai-io,项目名称:base,代码行数:23,代码来源:PGPEncryptionUtil.java

示例3: readSecretKey

import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; //导入依赖的package包/类
static PGPSecretKey readSecretKey() throws Exception {
    InputStream input = new ByteArrayInputStream(getSecKeyRing());
    PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection(PGPUtil.getDecoderStream(input),
                                                                       new BcKeyFingerprintCalculator());

    @SuppressWarnings("rawtypes")
    Iterator keyRingIter = pgpSec.getKeyRings();
    while (keyRingIter.hasNext()) {
        PGPSecretKeyRing keyRing = (PGPSecretKeyRing) keyRingIter.next();

        @SuppressWarnings("rawtypes")
        Iterator keyIter = keyRing.getSecretKeys();
        while (keyIter.hasNext()) {
            PGPSecretKey key = (PGPSecretKey) keyIter.next();

            if (key.isSigningKey()) {
                return key;
            }
        }
    }

    throw new IllegalArgumentException("Can't find signing key in key ring.");
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:24,代码来源:PGPDataFormatTest.java

示例4: checkSecretKeyRingWithPersonalCertificate

import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; //导入依赖的package包/类
private void checkSecretKeyRingWithPersonalCertificate(byte[] keyRing)
    throws Exception
{
    PGPSecretKeyRingCollection secCol = new PGPSecretKeyRingCollection(keyRing, new BcKeyFingerprintCalculator());


    int count = 0;

    for (Iterator rIt = secCol.getKeyRings(); rIt.hasNext();)
    {
        PGPSecretKeyRing ring = (PGPSecretKeyRing)rIt.next();

        for (Iterator it = ring.getExtraPublicKeys(); it.hasNext();)
        {
            it.next();
            count++;
        }
    }

    if (count != 1)
    {
        fail("personal certificate data subkey not found - count = " + count);
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:25,代码来源:BcPGPKeyRingTest.java

示例5: readSecretKey

import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; //导入依赖的package包/类
private static PGPSecretKey readSecretKey( InputStream is ) throws IOException, PGPException
{
    PGPSecretKeyRingCollection pgpSec =
            new PGPSecretKeyRingCollection( PGPUtil.getDecoderStream( is ), new JcaKeyFingerprintCalculator() );
    Iterator keyRingIter = pgpSec.getKeyRings();

    while ( keyRingIter.hasNext() )
    {
        PGPSecretKeyRing keyRing = ( PGPSecretKeyRing ) keyRingIter.next();
        Iterator keyIter = keyRing.getSecretKeys();

        while ( keyIter.hasNext() )
        {
            PGPSecretKey key = ( PGPSecretKey ) keyIter.next();

            if ( key.isSigningKey() )
            {
                return key;
            }
        }
    }

    throw new IllegalArgumentException( "Can't find signing key in key ring." );
}
 
开发者ID:subutai-io,项目名称:base,代码行数:25,代码来源:PGPKeyHelper.java

示例6: lookupKeyPair

import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; //导入依赖的package包/类
/**
 * Same as {@link #lookupPublicKey} but also retrieves the associated private key.
 *
 * @throws VerifyException if either keys couldn't be found.
 * @see #lookupPublicKey
 */
@SuppressWarnings("deprecation")
public static PGPKeyPair lookupKeyPair(
    PGPPublicKeyRingCollection publics,
    PGPSecretKeyRingCollection privates,
    String query,
    KeyRequirement want) {
  PGPPublicKey publicKey = lookupPublicKey(publics, query, want);
  PGPPrivateKey privateKey;
  try {
    PGPSecretKey secret = verifyNotNull(privates.getSecretKey(publicKey.getKeyID()),
        "Keyring missing private key associated with public key id: %x (query '%s')",
        publicKey.getKeyID(), query);
    // We do not support putting a password on the private key so we're just going to
    // put char[0] here.
    privateKey = secret.extractPrivateKey(
        new BcPBESecretKeyDecryptorBuilder(new BcPGPDigestCalculatorProvider())
            .build(new char[0]));
  } catch (PGPException e) {
    throw new VerifyException(e.getMessage());
  }
  return new PGPKeyPair(publicKey, privateKey);
}
 
开发者ID:google,项目名称:nomulus,代码行数:29,代码来源:PgpHelper.java

示例7: readSecretKey

import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; //导入依赖的package包/类
private PGPSecretKey readSecretKey() throws IOException, PGPException {
  PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection(
      PGPUtil.getDecoderStream(new ByteArrayInputStream(config.keypair.getBytes())),
      new JcaKeyFingerprintCalculator());

  Iterator<PGPSecretKeyRing> keyRings = pgpSec.getKeyRings();
  while (keyRings.hasNext()) {
    PGPSecretKeyRing keyRing = (PGPSecretKeyRing) keyRings.next();

    Iterator<PGPSecretKey> keys = keyRing.getSecretKeys();
    while (keys.hasNext()) {
      PGPSecretKey key = (PGPSecretKey) keys.next();

      if (key.isSigningKey()) {
        return key;
      }
    }
  }

  throw new IllegalStateException("Can't find signing key in key ring.");
}
 
开发者ID:sonatype-nexus-community,项目名称:nexus-repository-apt,代码行数:22,代码来源:AptSigningFacet.java

示例8: checkSecretKeyRingWithPersonalCertificate

import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; //导入依赖的package包/类
private void checkSecretKeyRingWithPersonalCertificate(byte[] keyRing)
    throws Exception
{
    PGPSecretKeyRingCollection secCol = new PGPSecretKeyRingCollection(keyRing);


    int count = 0;

    for (Iterator rIt = secCol.getKeyRings(); rIt.hasNext();)
    {
        PGPSecretKeyRing ring = (PGPSecretKeyRing)rIt.next();

        for (Iterator it = ring.getExtraPublicKeys(); it.hasNext();)
        {
            it.next();
            count++;
        }
    }

    if (count != 1)
    {
        fail("personal certificate data subkey not found - count = " + count);
    }
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:25,代码来源:BcPGPKeyRingTest.java

示例9: readSecretKey

import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; //导入依赖的package包/类
private static PGPSecretKey readSecretKey(InputStream input, String keyId)
		throws IOException, PGPException {
	for (@SuppressWarnings("unchecked")
	Iterator<PGPSecretKeyRing> keyRingIter = new PGPSecretKeyRingCollection(
			PGPUtil.getDecoderStream(input)).getKeyRings(); keyRingIter
			.hasNext();) {
		for (@SuppressWarnings("unchecked")
		Iterator<PGPSecretKey> keyIter = keyRingIter.next().getSecretKeys(); keyIter
				.hasNext();) {
			PGPSecretKey key = keyIter.next();
			String id = bytArrayToHex(key.getPublicKey().getFingerprint());
			if ((keyId == null || keyId.equalsIgnoreCase(id.substring(id
					.length() - 8))) && key.isSigningKey()) {
				return key;
			}
		}
	}
	throw new IllegalArgumentException("No signing key in keyring");
}
 
开发者ID:pfichtner,项目名称:crackgpg,代码行数:20,代码来源:GpgPassphraseChecker.java

示例10: readSecretKey

import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; //导入依赖的package包/类
protected PGPSecretKey readSecretKey(PGPSecretKeyRingCollection keyRings, final PgpKeyId keyId, String sourceDescription) {
    PGPSecretKey key = findSecretKey(keyRings, keyId);
    if (key == null) {
        throw new InvalidUserDataException("did not find secret key for id \'" + String.valueOf(keyId) + "\' in key source \'" + sourceDescription + "\'");
    }
    return key;
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:8,代码来源:PgpSignatoryFactory.java

示例11: findSecretKey

import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; //导入依赖的package包/类
@Nullable
private PGPSecretKey findSecretKey(PGPSecretKeyRingCollection keyRings, PgpKeyId keyId) {
    Iterator<PGPSecretKeyRing> keyRingIterator = uncheckedCast(keyRings.getKeyRings());
    while (keyRingIterator.hasNext()) {
        PGPSecretKeyRing keyRing = keyRingIterator.next();
        Iterator<PGPSecretKey> secretKeyIterator = uncheckedCast(keyRing.getSecretKeys());
        while (secretKeyIterator.hasNext()) {
            PGPSecretKey secretKey = secretKeyIterator.next();
            if (hasId(keyId, secretKey)) {
                return secretKey;
            }
        }
    }
    return null;
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:16,代码来源:PgpSignatoryFactory.java

示例12: readSecretKey

import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; //导入依赖的package包/类
public static PGPSecretKey readSecretKey(InputStream in)
	throws IOException, PGPException
{
	in = PGPUtil.getDecoderStream(in);
    PGPSecretKeyRingCollection keyRingCollection = new PGPSecretKeyRingCollection(in, new JcaKeyFingerprintCalculator());

    //
    // We just loop through the collection till we find a key suitable for signing.
    // In the real world you would probably want to be a bit smarter about this.
    //
    PGPSecretKey secretKey = null;

    Iterator<PGPSecretKeyRing> rIt = keyRingCollection.getKeyRings();
    while (secretKey == null && rIt.hasNext()) {
        PGPSecretKeyRing keyRing = rIt.next();
        Iterator<PGPSecretKey> kIt = keyRing.getSecretKeys();
        while (secretKey == null && kIt.hasNext()) {
            PGPSecretKey key = kIt.next();
            if (key.isSigningKey()) {
                secretKey = key;
            }
        }
    }

    // Validate secret key
    if (secretKey == null) {
        throw new IllegalArgumentException("Can't find private key in the key ring.");
    }
    if (!secretKey.isSigningKey()) {
        throw new IllegalArgumentException("Private key does not allow signing.");
    }
    if (secretKey.getPublicKey().isRevoked()) {
        throw new IllegalArgumentException("Private key has been revoked.");
    }

    return secretKey;
}
 
开发者ID:AnonymOnline,项目名称:saveOrganizer,代码行数:38,代码来源:KeyIO.java

示例13: readSecretKey

import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; //导入依赖的package包/类
/**
 * A simple routine that opens a key ring file and loads the first available
 * key suitable for signature generation.
 * 
 * @param input
 *            stream to read the secret key ring collection from.
 * @return a secret key.
 * @throws IOException
 *             on a problem with using the input stream.
 * @throws PGPException
 *             if there is an issue parsing the input stream.
 */
static PGPSecretKey readSecretKey(InputStream input) throws IOException, PGPException
{
	PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection(PGPUtil.getDecoderStream(input),
			new JcaKeyFingerprintCalculator());

	//
	// we just loop through the collection till we find a key suitable for
	// encryption, in the real
	// world you would probably want to be a bit smarter about this.
	//

	Iterator keyRingIter = pgpSec.getKeyRings();
	while (keyRingIter.hasNext())
	{
		PGPSecretKeyRing keyRing = (PGPSecretKeyRing) keyRingIter.next();

		Iterator keyIter = keyRing.getSecretKeys();
		while (keyIter.hasNext())
		{
			PGPSecretKey key = (PGPSecretKey) keyIter.next();

			if (key.isSigningKey())
			{
				return key;
			}
		}
	}

	throw new IllegalArgumentException("Can't find signing key in key ring.");
}
 
开发者ID:AnonymOnline,项目名称:saveOrganizer,代码行数:43,代码来源:PGPUtils.java

示例14: readSecretKey

import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; //导入依赖的package包/类
public static PGPSecretKey readSecretKey(InputStream in)
        throws IOException, PGPException, NoSuchProviderException {

    // Get the decoder stream (auto-disarming)
    in = PGPUtil.getDecoderStream(in);

    // Open the key ring
    PGPSecretKeyRingCollection coll = new PGPSecretKeyRingCollection(in);

    // Find key
    return readSecretKey(coll);
}
 
开发者ID:SoftwareAG,项目名称:webmethods-integrationserver-pgpencryption,代码行数:13,代码来源:PGPKeyReader.java

示例15: getKeyInfo

import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; //导入依赖的package包/类
public static String getKeyInfo(PGPSecretKeyRingCollection coll) {
    
    StringBuffer info = new StringBuffer();
    
    // Iterate through key rings
    Iterator<?> rings = coll.getKeyRings();
    while (rings.hasNext()) {
        PGPSecretKeyRing ring = (PGPSecretKeyRing)rings.next();
        Iterator<?> keys = ring.getSecretKeys();
        while (keys.hasNext()) {
            info.append(getKeyInfo((PGPSecretKey)keys.next())).append("\n");
        }
    }
    return info.toString();
}
 
开发者ID:SoftwareAG,项目名称:webmethods-integrationserver-pgpencryption,代码行数:16,代码来源:PGPKeyReader.java


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