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


Java PGPPublicKeyRing类代码示例

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


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

示例1: readPublicKey

import org.bouncycastle.openpgp.PGPPublicKeyRing; //导入依赖的package包/类
public static PGPPublicKey readPublicKey(InputStream in)
   throws IOException, PGPException {
in = PGPUtil.getDecoderStream(in);

PGPPublicKeyRingCollection pgpPub = new PGPPublicKeyRingCollection(in, new JcaKeyFingerprintCalculator() );
Iterator rIt = pgpPub.getKeyRings();

while (rIt.hasNext()) {
   PGPPublicKeyRing kRing = (PGPPublicKeyRing) rIt.next();
   Iterator kIt = kRing.getPublicKeys();

   while (kIt.hasNext()) {
       PGPPublicKey k = (PGPPublicKey) kIt.next();

       if (k.isEncryptionKey()) {
           return k;
       }
   }
}

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

示例2: load

import org.bouncycastle.openpgp.PGPPublicKeyRing; //导入依赖的package包/类
/**
 * Loads all keys from the specified input stream,
 * and adds them to this ring's existing list of keys.
 */
public List<Key> load(InputStream stream) throws IOException, PGPException {
    ArrayList<Key> keys = new ArrayList<Key>();

    Iterator packets = parse(unarmor(stream));
    while (packets.hasNext()) {
        Object packet = packets.next();

        if (packet instanceof PGPSecretKeyRing)
            keys.add(newKey((PGPSecretKeyRing) packet));
        else if (packet instanceof PGPPublicKeyRing)
            keys.add(newKey((PGPPublicKeyRing) packet));
    }

    this.keys.addAll(keys);
    return keys;
}
 
开发者ID:justinludwig,项目名称:jpgpj,代码行数:21,代码来源:Ring.java

示例3: test11

import org.bouncycastle.openpgp.PGPPublicKeyRing; //导入依赖的package包/类
private void test11()
    throws Exception
{
    PGPPublicKeyRing pubRing = new PGPPublicKeyRing(subKeyBindingKey, new BcKeyFingerprintCalculator());
    Iterator         it = pubRing.getPublicKeys();
    
    while (it.hasNext())
    {
        PGPPublicKey key = (PGPPublicKey)it.next();
        
        if (key.getValidSeconds() != 0)
        {
            fail("expiration time non-zero");
        }
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:17,代码来源:BcPGPKeyRingTest.java

示例4: readPublicKey

import org.bouncycastle.openpgp.PGPPublicKeyRing; //导入依赖的package包/类
public static PGPPublicKey readPublicKey( PGPPublicKeyRing keyRing ) throws PGPException
{
    try
    {
        Iterator keyIter = keyRing.getPublicKeys();

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

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

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

示例5: getPublicKeyWithKeyIdAndUserID

import org.bouncycastle.openpgp.PGPPublicKeyRing; //导入依赖的package包/类
/**
 * Determines a public key from the keyring collection which has a certain
 * key ID and which has a User ID which contains at least one of the User ID
 * parts.
 * 
 * @param keyId
 *            key ID
 * @param userIdParts
 *            user ID parts, can be empty, than no filter on the User ID is
 *            executed
 * @param publicKeyringCollection
 *            keyring collection
 * @return public key or <code>null</code> if no fitting key is found
 * @throws PGPException
 */
@SuppressWarnings("unchecked")
public static PGPPublicKey getPublicKeyWithKeyIdAndUserID(long keyId, List<String> userIdParts, PGPPublicKeyRingCollection publicKeyringCollection)
    throws PGPException {
    PGPPublicKeyRing publicKeyring = publicKeyringCollection.getPublicKeyRing(keyId);
    if (publicKeyring == null) {
        LOG.debug("No public key found for key ID {}.", Long.toString(keyId));
        return null;
    }
    // publicKey can be a subkey the user IDs must therefore be provided by the primary/master key
    if (isAllowedKey(userIdParts, publicKeyring.getPublicKey().getUserIDs())) {
        return publicKeyring.getPublicKey(keyId);
    } else {
        return null;
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:31,代码来源:PGPDataFormatUtil.java

示例6: lookupPublicKey

import org.bouncycastle.openpgp.PGPPublicKeyRing; //导入依赖的package包/类
/**
 * Search for public key on keyring based on a substring (like an email address).
 *
 * @throws VerifyException if the key couldn't be found.
 * @see #lookupKeyPair
 */
public static PGPPublicKey lookupPublicKey(
    PGPPublicKeyRingCollection keyring, String query, KeyRequirement want) {
  try {
    // Safe by specification.
    @SuppressWarnings("unchecked")
    Iterator<PGPPublicKeyRing> results =
        keyring.getKeyRings(checkNotNull(query, "query"), true, true);
    verify(results.hasNext(), "No public key found matching substring: %s", query);
    while (results.hasNext()) {
      Optional<PGPPublicKey> result = lookupPublicSubkey(results.next(), want);
      if (result.isPresent()) {
        return result.get();
      }
    }
    throw new VerifyException(String.format(
        "No public key (%s) found matching substring: %s", want, query));
  } catch (PGPException e) {
    throw new VerifyException(String.format(
        "Public key lookup with query %s failed: %s", query, e.getMessage()));
  }
}
 
开发者ID:google,项目名称:nomulus,代码行数:28,代码来源:PgpHelper.java

示例7: getPublicKey

import org.bouncycastle.openpgp.PGPPublicKeyRing; //导入依赖的package包/类
public PGPPublicKeyRing getPublicKey(final PgpKeyId keyId) {
    Validate.notNull(keyId, "Key ID required");
    InputStream in = null;
    try {
        final URL lookup = getKeyServerUrlToRetrieveKeyId(keyId);
        in = urlInputStreamService.openConnection(lookup);
        return getPublicKey(in);
    }
    catch (final Exception e) {
        throw new IllegalStateException("Public key ID '" + keyId
                + "' not available from key server", e);
    }
    finally {
        IOUtils.closeQuietly(in);
    }
}
 
开发者ID:gvSIGAssociation,项目名称:gvnix1,代码行数:17,代码来源:PgpServiceImpl.java

示例8: readPublicKey

import org.bouncycastle.openpgp.PGPPublicKeyRing; //导入依赖的package包/类
public static PGPPublicKey readPublicKey( InputStream is ) throws IOException, PGPException
{
    PGPPublicKeyRingCollection pgpPub =
            new PGPPublicKeyRingCollection( PGPUtil.getDecoderStream( is ), new JcaKeyFingerprintCalculator() );

    Iterator keyRingIter = pgpPub.getKeyRings();

    while ( keyRingIter.hasNext() )
    {
        PGPPublicKeyRing keyRing = ( PGPPublicKeyRing ) keyRingIter.next();
        Iterator keyIter = keyRing.getPublicKeys();

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

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

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

示例9: updateEnvironmentKey

import org.bouncycastle.openpgp.PGPPublicKeyRing; //导入依赖的package包/类
@Override
public void updateEnvironmentKey( final PublicKeyContainer publicKeyContainer )
{
    try
    {
        Preconditions.checkNotNull( publicKeyContainer );
        Preconditions.checkArgument( !Strings.isNullOrEmpty( publicKeyContainer.getKey() ) );
        Preconditions.checkArgument( !Strings.isNullOrEmpty( publicKeyContainer.getHostId() ) );
        Preconditions.checkNotNull( publicKeyContainer.getFingerprint() );

        final PGPPublicKeyRing pubKeyRing = PGPKeyUtil.readPublicKeyRing( publicKeyContainer.getKey() );
        localPeer.updatePeerEnvironmentPubKey( new EnvironmentId( publicKeyContainer.getHostId() ), pubKeyRing );
    }
    catch ( Exception e )
    {
        LOGGER.error( e.getMessage(), e );
        throw new WebApplicationException( Response.serverError().entity( e.getMessage() ).build() );
    }
}
 
开发者ID:subutai-io,项目名称:base,代码行数:20,代码来源:RestServiceImpl.java

示例10: addInitiatorPeerEnvironmentPubKey

import org.bouncycastle.openpgp.PGPPublicKeyRing; //导入依赖的package包/类
@Override
public void addInitiatorPeerEnvironmentPubKey( final String keyId, final String pek )
{
    try
    {
        Preconditions.checkArgument( !Strings.isNullOrEmpty( keyId ) );
        Preconditions.checkArgument( !Strings.isNullOrEmpty( pek ) );

        PGPPublicKeyRing pubKeyRing = PGPKeyUtil.readPublicKeyRing( pek );
        localPeer.addPeerEnvironmentPubKey( keyId, pubKeyRing );
    }
    catch ( Exception e )
    {
        LOGGER.error( e.getMessage(), e );
        throw new WebApplicationException( Response.serverError().entity( e.getMessage() ).build() );
    }
}
 
开发者ID:subutai-io,项目名称:base,代码行数:18,代码来源:RestServiceImpl.java

示例11: getPublicKeyId

import org.bouncycastle.openpgp.PGPPublicKeyRing; //导入依赖的package包/类
@Override
public Response getPublicKeyId( final String identityId )
{
    try
    {
        PGPPublicKeyRing pubRing = securityManager.getKeyManager().getPublicKeyRing( identityId );
        PGPPublicKey key = pubRing.getPublicKey();

        if ( key == null )
        {
            logger.info( " ************* Public Key not found with id:" + identityId );
            return Response.status( Response.Status.NOT_FOUND ).entity( "Object Not found" ).build();
        }
        else
        {
            return Response.ok( PGPKeyUtil.encodeNumericKeyId( key.getKeyID() ) ).build();
        }
    }
    catch ( Exception ex )
    {
        logger.info( " ************* Error ! Public Key not found with id:" + identityId, ex );
        return Response.status( Response.Status.NOT_FOUND ).entity( "Object Not found" ).build();
    }
}
 
开发者ID:subutai-io,项目名称:base,代码行数:25,代码来源:SecurityManagerRestImpl.java

示例12: addPeerEnvironmentPubKey

import org.bouncycastle.openpgp.PGPPublicKeyRing; //导入依赖的package包/类
@Override
public void addPeerEnvironmentPubKey( final String keyId, final PGPPublicKeyRing pek ) throws PeerException
{
    Preconditions.checkNotNull( keyId, "Invalid key ID" );
    Preconditions.checkNotNull( pek, "Public key ring is null" );


    try
    {
        String exportedPubKeyRing = securityManager.getEncryptionTool().armorByteArrayToString( pek.getEncoded() );
        peerWebClient.addPeerEnvironmentPubKey( keyId, exportedPubKeyRing );
    }
    catch ( IOException | PGPException e )
    {
        throw new PeerException( e.getMessage() );
    }
}
 
开发者ID:subutai-io,项目名称:base,代码行数:18,代码来源:RemotePeerImpl.java

示例13: rememberKey

import org.bouncycastle.openpgp.PGPPublicKeyRing; //导入依赖的package包/类
/**
 * Simply stores the key ID in {@link #discoveredKeyIds} for future
 * reference of all Key IDs we've come across. This method uses a
 * {@link PGPPublicKeyRing} to ensure the input is actually a valid key,
 * plus locating any key IDs that have signed the key.
 * <p>
 * Please note {@link #discoveredKeyIds} is not used for any key functions
 * of this class. It is simply for user interface convenience.
 * 
 * @param keyRing the key ID to store (required)
 */
@SuppressWarnings("unchecked")
private void rememberKey(final PGPPublicKeyRing keyRing) {
    final PGPPublicKey key = keyRing.getPublicKey();
    if (key != null) {
        final PgpKeyId keyId = new PgpKeyId(key);
        discoveredKeyIds.add(keyId);
        final Iterator<String> userIdIterator = key.getUserIDs();
        while (userIdIterator.hasNext()) {
            final String userId = userIdIterator.next();
            final Iterator<PGPSignature> signatureIterator = key
                    .getSignaturesForID(userId);
            while (signatureIterator.hasNext()) {
                final PGPSignature signature = signatureIterator.next();
                final PgpKeyId signatureKeyId = new PgpKeyId(signature);
                discoveredKeyIds.add(signatureKeyId);
            }
        }
    }
}
 
开发者ID:gvSIGAssociation,项目名称:gvnix1,代码行数:31,代码来源:PgpServiceImpl.java

示例14: signKey

import org.bouncycastle.openpgp.PGPPublicKeyRing; //导入依赖的package包/类
@Override
public PGPPublicKeyRing signKey( PGPSecretKeyRing sourceSecRing, PGPPublicKeyRing targetPubRing, int trustLevel )
{
    try
    {
        String sigId = PGPKeyUtil.encodeNumericKeyId( targetPubRing.getPublicKey().getKeyID() );

        targetPubRing = encryptionTool.signPublicKey( targetPubRing, sigId, sourceSecRing.getSecretKey(), "" );
    }
    catch ( Exception ignored )
    {
        //ignore
    }

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

示例15: savePublicKeyRing

import org.bouncycastle.openpgp.PGPPublicKeyRing; //导入依赖的package包/类
@Override
public void savePublicKeyRing( String identityId, int type, String keyringAsASCII )
{
    try
    {
        PGPPublicKeyRing pgpPublicKeyRing = PGPKeyUtil.readPublicKeyRing( keyringAsASCII );

        if ( pgpPublicKeyRing != null )
        {
            savePublicKeyRing( identityId, type, pgpPublicKeyRing );
        }
    }
    catch ( Exception ex )
    {
        LOG.error( " ******** Error storing Public key:" + ex.toString(), ex );
    }
}
 
开发者ID:subutai-io,项目名称:base,代码行数:18,代码来源:KeyManagerImpl.java


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