本文整理汇总了Java中org.bouncycastle.openpgp.PGPPublicKey.getUserIDs方法的典型用法代码示例。如果您正苦于以下问题:Java PGPPublicKey.getUserIDs方法的具体用法?Java PGPPublicKey.getUserIDs怎么用?Java PGPPublicKey.getUserIDs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.openpgp.PGPPublicKey
的用法示例。
在下文中一共展示了PGPPublicKey.getUserIDs方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: rememberKey
import org.bouncycastle.openpgp.PGPPublicKey; //导入方法依赖的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);
}
}
}
}
示例2: getKeySummaryIfPossible
import org.bouncycastle.openpgp.PGPPublicKey; //导入方法依赖的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";
}
示例3: findFirstKeyUserIdContainingOneOfTheParts
import org.bouncycastle.openpgp.PGPPublicKey; //导入方法依赖的package包/类
private static String[] findFirstKeyUserIdContainingOneOfTheParts(List<String> useridParts, PGPPublicKey primaryKey) {
String[] foundKeyUserIdForUserIdPart = null;
for (@SuppressWarnings("unchecked")
Iterator<String> iterator = primaryKey.getUserIDs(); iterator.hasNext();) {
String keyUserId = iterator.next();
for (String userIdPart : useridParts) {
if (keyUserId.contains(userIdPart)) {
foundKeyUserIdForUserIdPart = new String[] {keyUserId, userIdPart };
}
}
}
return foundKeyUserIdForUserIdPart;
}
示例4: parseKeyring
import org.bouncycastle.openpgp.PGPPublicKey; //导入方法依赖的package包/类
/**
* Read keyring and fetch keys and user ids
*
* @throws FileNotFoundException
* @throws IOException
* @throws PGPException
*/
private void parseKeyring() throws FileNotFoundException, IOException, PGPException {
// Reset the key table
this.gpgKeyData = new ArrayList<>();
// Read the keyring
FileInputStream in = new FileInputStream(this.gpgHomeDirectory + "/pubring.gpg");
Security.addProvider(new BouncyCastleProvider());
PGPPublicKeyRingCollection pubRings = new PGPPublicKeyRingCollection(in, new JcaKeyFingerprintCalculator());
Iterator rIt = pubRings.getKeyRings();
PGPPublicKey pubKey = null;
while (rIt.hasNext()) {
PGPPublicKeyRing pgpPub = (PGPPublicKeyRing) rIt.next();
try {
pubKey = pgpPub.getPublicKey();
} catch (Exception e) {
Logger.getLogger(GpgTableModel.class.getName()).log(Level.SEVERE, null, e);
continue;
}
Iterator it = pgpPub.getPublicKeys();
String userId = "unknown";
String keyId = "unkwown";
boolean firstKey = true;
boolean firstId = true;
while (it.hasNext()) {
PGPPublicKey pgpKey = (PGPPublicKey) it.next();
if (firstKey) {
keyId = Long.toHexString(pgpKey.getKeyID());
firstKey = false;
}
Iterator iid = pgpKey.getUserIDs();
while (iid.hasNext()) {
if (firstId) {
firstId = false;
userId = (String) iid.next();
} else {
iid.next();
}
}
}
this.gpgKeyData.add(new GpgTableModel.SimpleGpgKey(keyId, userId));
}
try {
in.close();
} catch (IOException ex) {
Logger.getLogger(GpgTableModel.class.getName()).log(Level.SEVERE, null, ex);
}
}
示例5: formatKeyRing
import org.bouncycastle.openpgp.PGPPublicKey; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private void formatKeyRing(final StringBuilder sb,
final PGPPublicKeyRing keyRing) {
final SimpleDateFormat sdf = new SimpleDateFormat(
"yyyy-MMM-dd HH:mm:ss Z");
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
final Iterator<PGPPublicKey> it = keyRing.getPublicKeys();
boolean first = true;
while (it.hasNext()) {
final PGPPublicKey pgpKey = it.next();
if (first) {
appendLine(sb, ">>>> KEY ID: " + new PgpKeyId(pgpKey) + " <<<<");
appendLine(
sb,
" More Info: "
+ pgpService
.getKeyServerUrlToRetrieveKeyInformation(new PgpKeyId(
pgpKey)));
appendLine(sb,
" Created: " + sdf.format(pgpKey.getCreationTime()));
appendLine(
sb,
" Fingerprint: "
+ new String(
Hex.encode(pgpKey.getFingerprint())));
appendLine(sb,
" Algorithm: "
+ getAlgorithm(pgpKey.getAlgorithm()));
final Iterator<String> userIdIterator = pgpKey.getUserIDs();
while (userIdIterator.hasNext()) {
final String userId = userIdIterator.next();
appendLine(sb, " User ID: " + userId);
final Iterator<PGPSignature> signatureIterator = pgpKey
.getSignaturesForID(userId);
while (signatureIterator.hasNext()) {
final PGPSignature signature = signatureIterator.next();
appendLine(sb, " Signed By: "
+ getKeySummaryIfPossible(new PgpKeyId(
signature)));
}
}
first = false;
}
else {
appendLine(sb, " Subkey ID: " + new PgpKeyId(pgpKey) + " ["
+ getAlgorithm(pgpKey.getAlgorithm()) + "]");
}
}
}
示例6: addUserInfoToSignature
import org.bouncycastle.openpgp.PGPPublicKey; //导入方法依赖的package包/类
/**
* Add user ID to signature file.
*
* <p>This adds information about the identity of the signer to the signature file. It's not
* required, but I'm guessing it could be a lifesaver if somewhere down the road, people lose
* track of the public keys and need to figure out how to verify a couple blobs. This would at
* least tell them which key to download from the MIT keyserver.
*
* <p>But the main reason why I'm using this is because I copied it from the code of another
* googler who was also uncertain about the precise reason why it's needed.
*/
private static void addUserInfoToSignature(PGPPublicKey publicKey, PGPSignatureGenerator signer) {
@SuppressWarnings("unchecked") // safe by specification.
Iterator<String> uidIter = publicKey.getUserIDs();
if (uidIter.hasNext()) {
PGPSignatureSubpacketGenerator spg = new PGPSignatureSubpacketGenerator();
spg.setSignerUserID(false, uidIter.next());
signer.setHashedSubpackets(spg.generate());
}
}
示例7: addUserInfoToSignature
import org.bouncycastle.openpgp.PGPPublicKey; //导入方法依赖的package包/类
/**
* Add user ID to signature file.
*
* <p>This adds information about the identity of the signer to the signature file. It's not
* required, but I'm guessing it could be a lifesaver if somewhere down the road, people lose
* track of the public keys and need to figure out how to verify a couple blobs. This would at
* least tell them which key to download from the MIT keyserver.
*
* <p>But the main reason why I'm using this is because I copied it from the code of another
* Googler who was also uncertain about the precise reason why it's needed.
*/
private void addUserInfoToSignature(PGPPublicKey publicKey, PGPSignatureGenerator signer) {
@SuppressWarnings("unchecked") // Safe by specification.
Iterator<String> uidIter = publicKey.getUserIDs();
if (uidIter.hasNext()) {
PGPSignatureSubpacketGenerator spg = new PGPSignatureSubpacketGenerator();
spg.setSignerUserID(false, uidIter.next());
signer.setHashedSubpackets(spg.generate());
}
}