本文整理汇总了Java中org.bouncycastle.openpgp.PGPPublicKeyRing.getPublicKeys方法的典型用法代码示例。如果您正苦于以下问题:Java PGPPublicKeyRing.getPublicKeys方法的具体用法?Java PGPPublicKeyRing.getPublicKeys怎么用?Java PGPPublicKeyRing.getPublicKeys使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.openpgp.PGPPublicKeyRing
的用法示例。
在下文中一共展示了PGPPublicKeyRing.getPublicKeys方法的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: 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");
}
}
}
示例3: 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;
}
示例4: 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." );
}
示例5: readPublicKey
import org.bouncycastle.openpgp.PGPPublicKeyRing; //导入方法依赖的package包/类
static PGPPublicKey readPublicKey(String keyringPath) throws Exception {
InputStream input = new ByteArrayInputStream(getKeyRing(keyringPath));
PGPPublicKeyRingCollection pgpPub = new PGPPublicKeyRingCollection(PGPUtil.getDecoderStream(input),
new BcKeyFingerprintCalculator());
@SuppressWarnings("rawtypes")
Iterator keyRingIter = pgpPub.getKeyRings();
while (keyRingIter.hasNext()) {
PGPPublicKeyRing keyRing = (PGPPublicKeyRing) keyRingIter.next();
@SuppressWarnings("rawtypes")
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.");
}
示例6: readPublicKey
import org.bouncycastle.openpgp.PGPPublicKeyRing; //导入方法依赖的package包/类
/**
* A simple routine that opens a key ring file and loads the first available
* key suitable for encryption.
*
* @param input
* data stream containing the public key data
* @return the first public key found.
* @throws IOException
* @throws PGPException
*/
static PGPPublicKey readPublicKey(InputStream input) throws IOException, PGPException
{
PGPPublicKeyRingCollection pgpPub = new PGPPublicKeyRingCollection(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 = 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.");
}
示例7: doInBackground
import org.bouncycastle.openpgp.PGPPublicKeyRing; //导入方法依赖的package包/类
@Override
protected Void doInBackground() throws Exception
{
Main.logger.info("Neue Schlüssel werden generiert...");
PGPKeyRingGenerator pkg = RSAGen.generateKeyRingGenerator(mail, pass, this);
PGPPublicKeyRing pkr = pkg.generatePublicKeyRing();
PGPSecretKeyRing skr = pkg.generateSecretKeyRing();
Main.psk = skr.getSecretKey();
Iterator<PGPPublicKey> rIt = pkr.getPublicKeys();
// Sucht den Verschlüsselungsschlüssel
while (Main.ppk == null && rIt.hasNext())
{
PGPPublicKey temp_key = rIt.next();
if (temp_key.isEncryptionKey())
{
Main.ppk = temp_key;
break;
}
}
PBESecretKeyDecryptor secretKeyDecryptor = new JcePBESecretKeyDecryptorBuilder()
.setProvider(BouncyCastleProvider.PROVIDER_NAME).build(pass);
Main.pprk = Main.psk.extractPrivateKey(secretKeyDecryptor);
setProgress(90);
// Speichern der Schlüssel
PGPSecretKeyRing pskr = pkg.generateSecretKeyRing();
ArmoredOutputStream secout = new ArmoredOutputStream(
new BufferedOutputStream(new FileOutputStream(Main.secKey)));
// Geheimer Schlüssel
pskr.encode(secout);
secout.close();
ArmoredOutputStream pubout = new ArmoredOutputStream(
new BufferedOutputStream(new FileOutputStream(Main.pubKey)));
pkr.encode(pubout);
pubout.close();
setProgress(100);
return null;
}
示例8: getKeyInfo
import org.bouncycastle.openpgp.PGPPublicKeyRing; //导入方法依赖的package包/类
public static String getKeyInfo(PGPPublicKeyRingCollection coll) {
StringBuffer info = new StringBuffer();
// Iterate through key rings
Iterator<?> rings = coll.getKeyRings();
while (rings.hasNext()) {
PGPPublicKeyRing ring = (PGPPublicKeyRing)rings.next();
Iterator<?> keys = ring.getPublicKeys();
while (keys.hasNext()) {
info.append(getKeyInfo((PGPPublicKey)keys.next())).append("\n");
}
}
return info.toString();
}
示例9: test6
import org.bouncycastle.openpgp.PGPPublicKeyRing; //导入方法依赖的package包/类
public void test6()
throws Exception
{
PGPPublicKeyRingCollection pubRings = new PGPPublicKeyRingCollection(pub6, new BcKeyFingerprintCalculator());
Iterator rIt = pubRings.getKeyRings();
while (rIt.hasNext())
{
PGPPublicKeyRing pgpPub = (PGPPublicKeyRing)rIt.next();
Iterator it = pgpPub.getPublicKeys();
while (it.hasNext())
{
PGPPublicKey k = (PGPPublicKey)it.next();
if (k.getKeyID() == 0x5ce086b5b5a18ff4L)
{
int count = 0;
Iterator sIt = k.getSignaturesOfType(PGPSignature.SUBKEY_REVOCATION);
while (sIt.hasNext())
{
PGPSignature sig = (PGPSignature)sIt.next();
count++;
}
if (count != 1)
{
fail("wrong number of revocations in test6.");
}
}
}
}
byte[] encRing = pubRings.getEncoded();
}
示例10: checkPublicKeyRingWithX509
import org.bouncycastle.openpgp.PGPPublicKeyRing; //导入方法依赖的package包/类
private void checkPublicKeyRingWithX509(byte[] keyRing)
throws Exception
{
PGPPublicKeyRing pubRing = new PGPPublicKeyRing(keyRing, new BcKeyFingerprintCalculator());
Iterator it = pubRing.getPublicKeys();
if (it.hasNext())
{
PGPPublicKey key = (PGPPublicKey)it.next();
Iterator sIt = key.getSignatures();
if (sIt.hasNext())
{
PGPSignature sig = (PGPSignature)sIt.next();
if (sig.getKeyAlgorithm() != 100)
{
fail("experimental signature not found");
}
if (!areEqual(sig.getSignature(), Hex.decode("000101")))
{
fail("experimental encoding check failed");
}
}
else
{
fail("no signature found");
}
}
else
{
fail("no key found");
}
}
示例11: testExtractingContentFromClearSign
import org.bouncycastle.openpgp.PGPPublicKeyRing; //导入方法依赖的package包/类
@Test
public void testExtractingContentFromClearSign()
{
PGPPublicKey key = null;
try
{
InputStream in = findFile( PLUGIN_PRIVATE_KEY );
in = org.bouncycastle.openpgp.PGPUtil.getDecoderStream( in );
JcaPGPPublicKeyRingCollection pgpPub = new JcaPGPPublicKeyRingCollection( in );
in.close();
Iterator<PGPPublicKeyRing> rIt = pgpPub.getKeyRings();
while ( key == null && rIt.hasNext() )
{
PGPPublicKeyRing kRing = rIt.next();
Iterator<PGPPublicKey> kIt = kRing.getPublicKeys();
while ( key == null && kIt.hasNext() )
{
PGPPublicKey k = kIt.next();
if ( k.isEncryptionKey() )
{
key = k;
}
}
}
}
catch ( Exception e )
{
e.printStackTrace();
}
}
示例12: isTrustedKey
import org.bouncycastle.openpgp.PGPPublicKeyRing; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private boolean isTrustedKey(final List<PGPPublicKeyRing> keys,
final String keyId) {
for (final PGPPublicKeyRing keyRing : keys) {
final Iterator<PGPPublicKey> it = keyRing.getPublicKeys();
while (it.hasNext()) {
final PGPPublicKey pgpKey = it.next();
if (new PgpKeyId(pgpKey).equals(new PgpKeyId(keyId))) {
return true;
}
}
}
return false;
}
示例13: getKeySummaryIfPossible
import org.bouncycastle.openpgp.PGPPublicKeyRing; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private String getKeySummaryIfPossible(final PgpKeyId keyId) {
final List<PGPPublicKeyRing> keyRings = pgpService.getTrustedKeys();
for (final PGPPublicKeyRing keyRing : keyRings) {
final Iterator<PGPPublicKey> it = keyRing.getPublicKeys();
while (it.hasNext()) {
final PGPPublicKey pgpKey = it.next();
if (new PgpKeyId(pgpKey.getKeyID()).equals(keyId)) {
// We know about this key, so return a one-liner
final StringBuilder sb = new StringBuilder();
sb.append("Key ").append(keyId).append(" (");
final Iterator<String> userIds = pgpKey.getUserIDs();
if (userIds.hasNext()) {
final String userId = userIds.next();
sb.append(userId);
}
else {
sb.append("no user ID in key");
}
sb.append(")");
return sb.toString();
}
}
}
return "Key " + keyId + " - not locally trusted";
}
示例14: readPublicKey
import org.bouncycastle.openpgp.PGPPublicKeyRing; //导入方法依赖的package包/类
/**
* Reads the public key from the specified key file.
*
* @param in - Stream pointing to key store.
* @param fingerPrintCalculator - An alogrithm to be used for fingerprint calculation.
* This sample uses BcKeyFingerprintCalculator algorithm.
* @return Returns a public key read from the specified key file.
* @throws IOException
* @throws PGPException
* @throws CryptDecryptException
*/
private PGPPublicKey readPublicKey() throws IOException, PGPException, CryptDecryptException {
if(enableDebugLog)Trace.logInfo("CryptDecryptUtil.readPublicKey", "Entry");
PGPPublicKey publicKey = null;
InputStream publicKeyStream = new FileInputStream(keyRing);
// Read the key file using BouncyCastle utility class to build a collection.
PGPPublicKeyRingCollection keyRingCollection = new PGPPublicKeyRingCollection(PGPUtil.getDecoderStream(publicKeyStream), fingerPrintCalculator);
// Iterate through the key rings to find a key that can be used for encryption
Iterator<PGPPublicKeyRing> rIt = keyRingCollection.getKeyRings();
while (publicKey == null && rIt.hasNext()) {
PGPPublicKeyRing kRing = rIt.next();
Iterator<PGPPublicKey> kIt = kRing.getPublicKeys();
while (publicKey == null && kIt.hasNext()) {
PGPPublicKey key = kIt.next();
if (key.isEncryptionKey()) {
publicKey = key;
}
}
}
// The key store does not contain any key.
if (publicKey == null) {
throw new CryptDecryptException("Can't find public key in the key ring.");
}
// Check if the key can be used for encryption. If not throw an exception
if (!isForEncryption(publicKey)) {
throw new CryptDecryptException("KeyID " + publicKey.getKeyID() + " not flagged for encryption.");
}
if(enableDebugLog)Trace.logInfo("CryptDecryptUtil.readPublicKey", "Exit");
return publicKey;
}
示例15: lookupPublicSubkey
import org.bouncycastle.openpgp.PGPPublicKeyRing; //导入方法依赖的package包/类
/**
* Return appropriate key or subkey for given task from public key.
*
* <p>Weirder older PGP public keys will actually have multiple keys. The main key will usually
* be sign-only in such situations. So you've gotta go digging in through the key packets and
* make sure you get the one that's valid for encryption, or whatever you want to do.
*/
public static Optional<PGPPublicKey> lookupPublicSubkey(
PGPPublicKeyRing ring, KeyRequirement want) {
// Safe by specification.
@SuppressWarnings("unchecked")
Iterator<PGPPublicKey> keys = ring.getPublicKeys();
while (keys.hasNext()) {
PGPPublicKey key = keys.next();
switch (want) {
case ENCRYPT:
if (key.isEncryptionKey()) {
return Optional.of(key);
}
break;
case SIGN:
if (isSigningKey(key)) {
return Optional.of(key);
}
break;
case ENCRYPT_SIGN:
if (key.isEncryptionKey() && isSigningKey(key)) {
return Optional.of(key);
}
break;
default:
throw new AssertionError();
}
}
return Optional.empty();
}