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


Java PGPSecretKeyRing.getSecretKeys方法代码示例

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


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

示例1: readSecretKey

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

示例2: getSecretKey

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

示例3: readSecretKey

import org.bouncycastle.openpgp.PGPSecretKeyRing; //导入方法依赖的package包/类
public static PGPSecretKey readSecretKey( PGPSecretKeyRing keyRing ) throws PGPException
{
    try
    {
        Iterator keyIter = keyRing.getSecretKeys();

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

            if ( key.isSigningKey() )
            {
                return key;
            }
        }
    }
    catch ( Exception e )
    {
        LOG.error( e.getMessage() );
    }

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

示例4: readSecretKey

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

示例5: readSecretKey

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

示例6: readSecretKey

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

示例7: readSecretKey

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

示例8: getKeyInfo

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

示例9: addPrivateKeyToKeyring

import org.bouncycastle.openpgp.PGPSecretKeyRing; //导入方法依赖的package包/类
static public void addPrivateKeyToKeyring(final String gpgHomeDirectory, final String keyringFile) throws FileNotFoundException, IOException, PGPException {
    Security.addProvider(new BouncyCastleProvider());

    // Read user secret keyring
    FileInputStream inPriv = new FileInputStream(gpgHomeDirectory + "/secring.gpg");
    PGPSecretKeyRingCollection privRings = new PGPSecretKeyRingCollection(inPriv, new JcaKeyFingerprintCalculator());

    // Read keys (public and private) from armored file
    PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection(
        PGPUtil.getDecoderStream(new FileInputStream(keyringFile)), new JcaKeyFingerprintCalculator());

    // Iterate over the keys
    Iterator keyRingIter = pgpSec.getKeyRings();
    while (keyRingIter.hasNext()) {
        PGPSecretKeyRing keyRing = (PGPSecretKeyRing) keyRingIter.next();
        privRings = PGPSecretKeyRingCollection.addSecretKeyRing(privRings, keyRing);

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

            if (key.isSigningKey()) {
                System.out.println("Private key imported " + Long.toHexString(key.getKeyID()).toUpperCase());
            }
        }
    }

    try (FileOutputStream out = new FileOutputStream(new File(gpgHomeDirectory + "/secring.gpg"))) {
        privRings.encode(out);
    }
}
 
开发者ID:fjoncourt,项目名称:jfwknop,代码行数:32,代码来源:GpgUtils.java

示例10: rewrapTest

import org.bouncycastle.openpgp.PGPSecretKeyRing; //导入方法依赖的package包/类
private void rewrapTest()
    throws Exception
{
    SecureRandom rand = new SecureRandom();

    // Read the secret key rings
    PGPSecretKeyRingCollection privRings = new PGPSecretKeyRingCollection(
                                                     new ByteArrayInputStream(rewrapKey), new BcKeyFingerprintCalculator());

    Iterator rIt = privRings.getKeyRings();

    if (rIt.hasNext())
    {
        PGPSecretKeyRing pgpPriv = (PGPSecretKeyRing)rIt.next();

        Iterator it = pgpPriv.getSecretKeys();

        while (it.hasNext())
        {
            PGPSecretKey pgpKey = (PGPSecretKey)it.next();

            // re-encrypt the key with an empty password
            pgpPriv = PGPSecretKeyRing.removeSecretKey(pgpPriv, pgpKey);
            pgpKey = PGPSecretKey.copyWithNewPassword(
                                pgpKey,
                                new BcPBESecretKeyDecryptorBuilder(new BcPGPDigestCalculatorProvider()).build(rewrapPass),
                                null);
            pgpPriv = PGPSecretKeyRing.insertSecretKey(pgpPriv, pgpKey);
        
            // this should succeed
            PGPPrivateKey privTmp = pgpKey.extractPrivateKey(null);
        }
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:35,代码来源:BcPGPKeyRingTest.java

示例11: findSecretKeysWithPrivateKeyAndUserId

import org.bouncycastle.openpgp.PGPSecretKeyRing; //导入方法依赖的package包/类
public static List<PGPSecretKeyAndPrivateKeyAndUserId> findSecretKeysWithPrivateKeyAndUserId(Map<String, String> sigKeyUserId2Password,
        String provider, PGPSecretKeyRingCollection pgpSec) throws PGPException {
    List<PGPSecretKeyAndPrivateKeyAndUserId> result = new ArrayList<PGPSecretKeyAndPrivateKeyAndUserId>(sigKeyUserId2Password.size());
    for (Iterator<?> i = pgpSec.getKeyRings(); i.hasNext();) {
        Object data = i.next();
        if (data instanceof PGPSecretKeyRing) {
            PGPSecretKeyRing keyring = (PGPSecretKeyRing) data;
            PGPSecretKey primaryKey = keyring.getSecretKey();
            List<String> useridParts = new ArrayList<String>(sigKeyUserId2Password.keySet());
            String[] foundKeyUserIdForUserIdPart = findFirstKeyUserIdContainingOneOfTheParts(useridParts, primaryKey.getPublicKey());
            if (foundKeyUserIdForUserIdPart == null) {
                LOG.debug("No User ID found in primary key with key ID {} containing one of the parts {}", primaryKey.getKeyID(),
                        useridParts);
                continue;
            }
            LOG.debug("User ID {} found in primary key with key ID {} containing one of the parts {}", new Object[] {
                foundKeyUserIdForUserIdPart[0], primaryKey.getKeyID(), useridParts });
            // add all signing keys
            for (Iterator<PGPSecretKey> iterKey = keyring.getSecretKeys(); iterKey.hasNext();) {
                PGPSecretKey secKey = iterKey.next();
                if (isSigningKey(secKey)) {
                    PGPPrivateKey privateKey = secKey.extractPrivateKey(new JcePBESecretKeyDecryptorBuilder().setProvider(provider)
                            .build(sigKeyUserId2Password.get(foundKeyUserIdForUserIdPart[1]).toCharArray()));
                    if (privateKey != null) {
                        result.add(new PGPSecretKeyAndPrivateKeyAndUserId(secKey, privateKey, foundKeyUserIdForUserIdPart[0]));
                        LOG.debug("Private key with user ID {} and key ID {} added to the signing keys",
                                foundKeyUserIdForUserIdPart[0], Long.toString(privateKey.getKeyID()));

                    }
                }
            }
        }
    }
    return result;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:36,代码来源:PGPDataFormatUtil.java

示例12: readFirstSecretKey

import org.bouncycastle.openpgp.PGPSecretKeyRing; //导入方法依赖的package包/类
private static PGPSecretKey readFirstSecretKey(InputStream keyRingIs) {
    for (final PGPSecretKeyRing keyRing : extractSecrectKeyRings(keyRingIs)) {
        final Iterator<PGPSecretKey> keyIter = keyRing.getSecretKeys();
        while (keyIter.hasNext()) {
            final PGPSecretKey key = keyIter.next();
            if (key.isSigningKey()) {
                return key;
            }
        }
    }
    throw new IllegalArgumentException("Can't find signing key in key ring.");
}
 
开发者ID:jerkar,项目名称:jerkar,代码行数:13,代码来源:PgpUtils.java

示例13: loadSecretKey

import org.bouncycastle.openpgp.PGPSecretKeyRing; //导入方法依赖的package包/类
public static PGPSecretKey loadSecretKey ( final InputStream input, final String keyId ) throws IOException, PGPException
{
    final long keyIdNum = Long.parseUnsignedLong ( keyId, 16 );

    final BcPGPSecretKeyRingCollection keyrings = new BcPGPSecretKeyRingCollection ( PGPUtil.getDecoderStream ( input ) );

    final Iterator<?> keyRingIter = keyrings.getKeyRings ();
    while ( keyRingIter.hasNext () )
    {
        final PGPSecretKeyRing secretKeyRing = (PGPSecretKeyRing)keyRingIter.next ();

        final Iterator<?> secretKeyIterator = secretKeyRing.getSecretKeys ();
        while ( secretKeyIterator.hasNext () )
        {
            final PGPSecretKey key = (PGPSecretKey)secretKeyIterator.next ();

            if ( !key.isSigningKey () )
            {
                continue;
            }

            final long shortId = key.getKeyID () & 0xFFFFFFFFL;

            if ( key.getKeyID () != keyIdNum && shortId != keyIdNum )
            {
                continue;
            }

            return key;
        }
    }

    return null;
}
 
开发者ID:eclipse,项目名称:packagedrone,代码行数:35,代码来源:PgpHelper.java

示例14: readSecretKey

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

    //
    // 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:petrsmid,项目名称:unicredit-connector,代码行数:39,代码来源:BouncyCastlePGPExampleUtil.java

示例15: readSecretKey

import org.bouncycastle.openpgp.PGPSecretKeyRing; //导入方法依赖的package包/类
/**
 * <p>Return the first suitable key for signing in the key ring
 * collection. For this case we only expect there to be one key
 * available for signing.</p>
 * 
 * @param input - the input stream of the PGP key ring
 * @return the first suitable PGP secret key found for signing
 * @throws IOException on I/O related errors
 * @throws PGPException on signing errors
 */
private static PGPSecretKey readSecretKey(InputStream input) throws IOException, PGPException {
        PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection(PGPUtil.getDecoderStream(input));
        PGPSecretKey secKey = null;

        @SuppressWarnings("unchecked")
        Iterator<PGPSecretKeyRing> iter = pgpSec.getKeyRings();
        while (iter.hasNext() && secKey == null) {
                PGPSecretKeyRing keyRing = iter.next();

                @SuppressWarnings("unchecked")
                Iterator<PGPSecretKey> keyIter = keyRing.getSecretKeys();
                while (keyIter.hasNext()) {
                        PGPSecretKey key = keyIter.next();
                        if (key.isSigningKey()) {
                                secKey = key;
                                break;
                        }
                }
        }

        if (secKey != null) {
                return secKey;
        }
        else {
                throw new IllegalArgumentException("Can't find signing key in key ring.");
        }
}
 
开发者ID:george-haddad,项目名称:bouncycastle,代码行数:38,代码来源:PGPCryptoTools.java


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