本文整理汇总了Java中org.bouncycastle.openpgp.PGPPublicKeyRingCollection.getKeyRings方法的典型用法代码示例。如果您正苦于以下问题:Java PGPPublicKeyRingCollection.getKeyRings方法的具体用法?Java PGPPublicKeyRingCollection.getKeyRings怎么用?Java PGPPublicKeyRingCollection.getKeyRings使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.openpgp.PGPPublicKeyRingCollection
的用法示例。
在下文中一共展示了PGPPublicKeyRingCollection.getKeyRings方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readPublicKey
import org.bouncycastle.openpgp.PGPPublicKeyRingCollection; //导入方法依赖的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: readPublicKey
import org.bouncycastle.openpgp.PGPPublicKeyRingCollection; //导入方法依赖的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." );
}
示例3: lookupPublicKey
import org.bouncycastle.openpgp.PGPPublicKeyRingCollection; //导入方法依赖的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()));
}
}
示例4: readPublicKey
import org.bouncycastle.openpgp.PGPPublicKeyRingCollection; //导入方法依赖的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.");
}
示例5: createKeyFrom
import org.bouncycastle.openpgp.PGPPublicKeyRingCollection; //导入方法依赖的package包/类
public PGPPublicKey createKeyFrom(InputStream in) throws IOException, PGPException {
InputStream pgpData = PGPUtil.getDecoderStream(in);
PGPPublicKeyRingCollection pgpPub = new PGPPublicKeyRingCollection(
PGPUtil.getDecoderStream(pgpData), 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.");
}
示例6: if
import org.bouncycastle.openpgp.PGPPublicKeyRingCollection; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private final static List<Result> validate
(CHkpSearch.Info candidate, String q, IGetter getter)
throws IOException
{
List<Result> ret = new ArrayList<Result>();
if (shouldSkip(candidate, q)) { return ret; }
// 1. pull down keys from the candidate.
PGPPublicKeyRingCollection pkrc = CHkpSearch.get
(candidate.getKeyId(), getter);
if ((pkrc == null) || (pkrc.size() <= 0)) {
return ret;
}
// 2. Validate each keyring.
Iterator<PGPPublicKeyRing> pkrit = pkrc.getKeyRings();
while (pkrit.hasNext()) {
Result r = validateKeyRing(pkrit.next(), q, getter);
if (r != null) { ret.add(r); }
}
return ret;
}
示例7: readPublicKey
import org.bouncycastle.openpgp.PGPPublicKeyRingCollection; //导入方法依赖的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.");
}
示例8: getKeyInfo
import org.bouncycastle.openpgp.PGPPublicKeyRingCollection; //导入方法依赖的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.PGPPublicKeyRingCollection; //导入方法依赖的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: getTrustedKeys
import org.bouncycastle.openpgp.PGPPublicKeyRingCollection; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public List<PGPPublicKeyRing> getTrustedKeys() {
if (!ROO_PGP_FILE.exists()) {
return new ArrayList<PGPPublicKeyRing>();
}
FileInputStream fis = null;
try {
fis = new FileInputStream(ROO_PGP_FILE);
final PGPPublicKeyRingCollection pubRings = new PGPPublicKeyRingCollection(
PGPUtil.getDecoderStream(fis));
final Iterator<PGPPublicKeyRing> rIt = pubRings.getKeyRings();
final List<PGPPublicKeyRing> result = new ArrayList<PGPPublicKeyRing>();
while (rIt.hasNext()) {
final PGPPublicKeyRing pgpPub = rIt.next();
rememberKey(pgpPub);
result.add(pgpPub);
}
return result;
}
catch (final Exception e) {
throw new IllegalArgumentException(
"Unable to get trusted keys",
ObjectUtils.defaultIfNull(ExceptionUtils.getRootCause(e), e));
}
finally {
IOUtils.closeQuietly(fis);
}
}
示例11: readPublicKey
import org.bouncycastle.openpgp.PGPPublicKeyRingCollection; //导入方法依赖的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;
}
示例12: findPublicKeys
import org.bouncycastle.openpgp.PGPPublicKeyRingCollection; //导入方法依赖的package包/类
public static List<PGPPublicKey> findPublicKeys(List<String> useridParts, boolean forEncryption, PGPPublicKeyRingCollection pgpPublicKeyringCollection) {
List<PGPPublicKey> result = new ArrayList<PGPPublicKey>(useridParts.size());
for (Iterator<PGPPublicKeyRing> keyRingIter = pgpPublicKeyringCollection.getKeyRings(); keyRingIter.hasNext();) {
PGPPublicKeyRing keyRing = keyRingIter.next();
PGPPublicKey primaryKey = keyRing.getPublicKey();
String[] foundKeyUserIdForUserIdPart = findFirstKeyUserIdContainingOneOfTheParts(useridParts, primaryKey);
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 adequate keys to the result
for (Iterator<PGPPublicKey> keyIter = keyRing.getPublicKeys(); keyIter.hasNext();) {
PGPPublicKey key = keyIter.next();
if (forEncryption) {
if (isEncryptionKey(key)) {
LOG.debug("Public encryption key with key user ID {} and key ID {} added to the encryption keys",
foundKeyUserIdForUserIdPart[0], Long.toString(key.getKeyID()));
result.add(key);
}
} else if (!forEncryption && isSignatureKey(key)) {
// not used!
result.add(key);
LOG.debug("Public key with key user ID {} and key ID {} added to the signing keys", foundKeyUserIdForUserIdPart[0],
Long.toString(key.getKeyID()));
}
}
}
return result;
}
示例13: readPublicKey
import org.bouncycastle.openpgp.PGPPublicKeyRingCollection; //导入方法依赖的package包/类
/**
* A simple routine that opens a key ring file and loads the first available key
* suitable for encryption.
*
* @param input
* @return
* @throws IOException
* @throws PGPException
*/
static PGPPublicKey readPublicKey(InputStream input) throws IOException, PGPException
{
PGPPublicKeyRingCollection pgpPub = new PGPPublicKeyRingCollection(
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 = 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.");
}
示例14: readPublicKey
import org.bouncycastle.openpgp.PGPPublicKeyRingCollection; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
private static PGPPublicKey readPublicKey(InputStream in)
throws IOException, PGPException {
in = PGPUtil.getDecoderStream(in);
PGPPublicKeyRingCollection pgpPub = new BcPGPPublicKeyRingCollection(in);
//
// 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.
//
//
// iterate through the key rings.
//
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.");
}
示例15: readPublicKey
import org.bouncycastle.openpgp.PGPPublicKeyRingCollection; //导入方法依赖的package包/类
/**
* <p>Return the first suitable key for encryption in the key ring
* collection. For this case we only expect there to be one key available
* for encryption.</p>
*
* @param input - the input stream of the PGP key ring
* @return the first suitable PGP public key found for encryption
* @throws IOException on I/O related errors
* @throws PGPException on signing errors
*/
private static final PGPPublicKey readPublicKey(InputStream input) throws IOException, PGPException {
PGPPublicKeyRingCollection pgpPub = new PGPPublicKeyRingCollection(PGPUtil.getDecoderStream(input));
PGPPublicKey pubKey = null;
@SuppressWarnings("unchecked")
Iterator<PGPPublicKeyRing> keyRingIter = pgpPub.getKeyRings();
while (keyRingIter.hasNext() && pubKey == null) {
PGPPublicKeyRing keyRing = keyRingIter.next();
@SuppressWarnings("unchecked")
Iterator<PGPPublicKey> keyIter = keyRing.getPublicKeys();
while (keyIter.hasNext()) {
PGPPublicKey key = keyIter.next();
if (key.isEncryptionKey()) {
pubKey = key;
break;
}
}
}
if (pubKey != null) {
return pubKey;
}
else {
throw new IllegalArgumentException("Can't find encryption key in key ring.");
}
}