本文整理汇总了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.");
}
示例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;
}
示例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");
}
}
}
示例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;
}
示例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;
}
}
示例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()));
}
}
示例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);
}
}
示例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." );
}
示例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() );
}
}
示例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() );
}
}
示例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();
}
}
示例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() );
}
}
示例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);
}
}
}
}
示例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;
}
示例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 );
}
}